Backup WordPress Database and Site Content

It is important that you backup your WordPress database and site content.  There are lots of options including using rsync to a remote server, using something like cloud storage.

I have two cron jobs running used to backup the database and site content. To set them up you need to use crontab

crontab -e

Then add you schedules to this:

00 07 * * * mysqldump -u root -pYOURPASSWORD DBNAME | gzip > /home/USER/backups/WordPress.sql$(date -u +\%Y\%m\%d).gz
00 08 * * * tar -zcPf /home/USER/backups/WordPress-SiteContent$(date -u +\%Y\%m\%d).gz /var/www/

Both of the backup files are compressed.  To recover these you will need to use the following commands:

MySQL Database
gzip -d WordPress.sql20121222.gz

WordPress Site Content
tar -zxvf WordPress20121222.gz

So that your backups do not fill up your disk, you can add the job that will purge your backup folder after x days.  To do this add another cron job (note this job purge files older than 3 days):

crontab -e

00 21 * * * find /home/USER/backups/*.gz -type f -mtime +3 -exec rm {} \;