provisioning tool for building opinionated architecture
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

44 lines
1.2 KiB

#!/bin/bash
function detectWordpress() {
local result=$(pwd)
while [[ ! ("$result" == / || -f "$result/wp-config.php") ]]; do
result=$(dirname "$result")
done
if [[ "$result" == / ]]; then
echo >&2 "no WORDPRESS detected from current folder <$(pwd)>!"
exit 100
fi
echo "$result"
}
## MAIN
## ----
set -Eeuo pipefail
WP_BASE=$(detectWordpress)
WP_CONFIG="$WP_BASE/wp-config.php"
DB_HOST=$(grep DB_HOST $WP_CONFIG | cut -d"'" -f4)
DB_NAME=$(grep DB_NAME $WP_CONFIG | cut -d"'" -f4)
DB_USER=$(grep DB_USER $WP_CONFIG | cut -d"'" -f4)
DB_PASSWORD=$(grep DB_PASSWORD $WP_CONFIG | cut -d"'" -f4)
TODAY=$(date +%F)
BACKUP_DIR="/mnt/SHARED/wordpress-backup/$DB_NAME-$TODAY"
[[ -d "$BACKUP_DIR" ]] && find "$BACKUP_DIR" -mindepth 1 -delete || mkdir -p "$BACKUP_DIR"
echo -n "backing up database..."
mariadb-dump -h "$DB_HOST" -u "$DB_NAME" -p"$DB_PASSWORD" "$DB_NAME" | gzip >"$BACKUP_DIR/$DB_NAME".mariadb.gz
echo OK
echo -n "compressing as tar.gz the wp-content folder ..."
tar -czvf "$BACKUP_DIR/wp-content.tgz" -C "$WP_BASE" wp-content
echo OK
echo -n "copying wp-config.php file ..."
cp "$WP_BASE/wp-config.php" "$BACKUP_DIR"
echo OK
echo "successful backup in $BACKUP_DIR, db + wp-content + wp-config"