Skip to content

Instantly share code, notes, and snippets.

@aksiksi
Last active May 29, 2022 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aksiksi/51da59e81f076a861396559d3961b4ac to your computer and use it in GitHub Desktop.
Save aksiksi/51da59e81f076a861396559d3961b4ac to your computer and use it in GitHub Desktop.
Backup Wordpress DB to Backblaze using rclone

Prerequisites

  1. Install rclone: curl https://rclone.org/install.sh | sudo bash
  2. Setup a new Backblaze B2 target: https://rclone.org/b2/

cron

Install a new crontab to run this script daily:

$ crontab -l
30 15 * * * /home/www/db-backup.sh 2>&1>> /tmp/db.log
#!/bin/bash
DATE="$(date +'%Y-%m-%d')"
BLOG_NAME=my-db-backup
BACKUP_DIR=/home/www/backups
BACKUP_FILE=$BACKUP_DIR/$BLOG_NAME-db-$DATE.sql.gz
WP_DB_NAME=wordpress
WP_USER=user
WP_PASS=password
BACKBLAZE_BUCKET=my-backups
/usr/bin/mysqldump --user=$WP_USER --password="$WP_PASS" $WP_DB_NAME | gzip > $BACKUP_FILE
rclone copy $BACKUP_FILE b2:$BACKBLAZE_BUCKET
# Keep only the last 30 days worth of backups
rclone delete b2:$BACKBLAZE_BUCKET --min-age 30d
# Cleanup the local backups dir
rm /home/www/backups/*.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment