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

9 months ago
  1. #!/bin/bash
  2. function detectWordpress() {
  3. local result=$(pwd)
  4. while [[ ! ("$result" == / || -f "$result/wp-config.php") ]]; do
  5. result=$(dirname "$result")
  6. done
  7. if [[ "$result" == / ]]; then
  8. echo >&2 "no WORDPRESS detected from current folder <$(pwd)>!"
  9. exit 100
  10. fi
  11. echo "$result"
  12. }
  13. ## MAIN
  14. ## ----
  15. set -Eeuo pipefail
  16. WP_BASE=$(detectWordpress)
  17. WP_CONFIG="$WP_BASE/wp-config.php"
  18. DB_HOST=$(grep DB_HOST $WP_CONFIG | cut -d"'" -f4)
  19. DB_NAME=$(grep DB_NAME $WP_CONFIG | cut -d"'" -f4)
  20. DB_USER=$(grep DB_USER $WP_CONFIG | cut -d"'" -f4)
  21. DB_PASSWORD=$(grep DB_PASSWORD $WP_CONFIG | cut -d"'" -f4)
  22. TODAY=$(date +%F)
  23. BACKUP_DIR="/mnt/SHARED/wordpress-backup/$DB_NAME-$TODAY"
  24. [[ -d "$BACKUP_DIR" ]] && find "$BACKUP_DIR" -mindepth 1 -delete || mkdir -p "$BACKUP_DIR"
  25. echo -n "backing up database..."
  26. mariadb-dump -h "$DB_HOST" -u "$DB_NAME" -p"$DB_PASSWORD" "$DB_NAME" | gzip >"$BACKUP_DIR/$DB_NAME".mariadb.gz
  27. echo OK
  28. echo -n "compressing as tar.gz the wp-content folder ..."
  29. tar -czvf "$BACKUP_DIR/wp-content.tgz" -C "$WP_BASE" wp-content
  30. echo OK
  31. echo -n "copying wp-config.php file ..."
  32. cp "$WP_BASE/wp-config.php" "$BACKUP_DIR"
  33. echo OK
  34. echo "successful backup in $BACKUP_DIR, db + wp-content + wp-config"