I had the following criteria when configuring the backup for my WordPress installation:
This approach is based on the script from the WordPress Backup Guide at theme.fm.
In addition to your
webserver_user, create a
backup_user account. The
backup_user will have read access to the website files; however, the
webserver_user will not have read access to the backups.
Configure the Accounts
backup_user and run
ssh-keygen -t rsa -b <keysize>. Keysize should be 2048 or 4096 (pick the bigger size for more security). Accept all of the defaults. Run
cat ~/.ssh/id_rsa.pub and copy the output. Create
chmod go-rw ~/backup.
webserver_user and edit/create
~/.ssh/authorized_keys. Add the key copied from
Create the following files and make the *.sh files executable:
[client] host=<mysql_server> user=<mysql_username> password=<mysql_password>
#!/bin/bash # Make sure we're working in the scripts directory cd /home/webserver_user/scripts # Backup the datbase mysqldump --defaults-file=/home/webserver_user/scripts/opts <wp_datbase> > db.sql # tar the database backup and all of the WordPress files # --transform is not necessary, but removes home/webserver_user from the path when extracting tar czf website-$(date +%Y-%m-%d).tar.gz --transform s,^home/webserver_user/www,www, db.sql /home/webserver_user/www # Cleanup by removing the uncompressed database backup rm db.sql
#!/bin/bash # Set the working directory cd /home/backup_user/backup # Run the save.sh script as the webserver_user ssh email@example.com /home/webserver_user/scripts/save.sh # Copy the backup to the backup_user account scp firstname.lastname@example.org:/home/webserver_user/scripts/*.tar.gz ./ # Remove the copy of the backup from the webserver_user ssh email@example.com 'rm /home/webserver_user/scripts/*.tar.gz' # cleanup the backup directory and only keep the 3 most recent backups while [ "$(ls -1t | wc -l)" -gt 3 ]; do rm "$(ls -t1r | head -n 1)" done
- Go to you Dreamhost Web Panel
- Go to Main menu → Goodies → Cron Jobs
- Click "Add New Cron Job"
- Select User
- Title: backup
- Email address if you want notification of the script running
- Command to run:
- When to run: daily or weekly
- Select User