second commit
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#!/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"
|
||||
Reference in New Issue
Block a user