x
 
Create New Page
 View Previous Changes    ( Last updated by Paul Wenzel )

Incremental Backups

This is the bare bones automated backup system I put in place for one of my own Expression Engine sites. The goal is to have daily snapshots with auto-rotation. In this situation, we have both a staging site and a live site that require daily snapshots. This system works well on shared Linux/Unix hosts with Cron and SSH access.

MySQL databases are backed up every day using a helpful script called automysqlbackup.sh:
http://sourceforge.net/projects/automysqlbackup/

This script bzip2’s (gzip also supported) the staging and live databases and rotates them on a daily, weekly, and monthly schedule.

For the web application files (CMS, htaccess, static files, etc), we use rsync and cp, following the instructions here:
http://www.mikerubel.org/computers/rsync_snapshots/#Incremental

The script rotates 3 days worth of snapshots and rsyncs the most recent version in the folder “~/webappps_backup”. It is pretty efficient with regard to system resources. I made separate versions for both staging and live sites.

Here is a generic example:

#Automated Snapshots Example (simplified version)
mv backup.3 backup.tmp
mv backup.2 backup.3
mv backup.1 backup.2
mv backup.0 backup.1
mv backup
.tmp backup.0
cp 
-al backup.1/. backup.0
rsync 
---delete source_directorybackup.0

This is the full script which creates snapshots of both staging and live sites.

Replace username with your own.

# webapps_backup.sh
# Automated Snapshot-Style Backups with Linux and Rsync
# http://www.mikerubel.org/computers/rsync_snapshots/

# Live Site Snapshot
mv /home/username/backup_webapps/ee_live.3 /home/username/backup_webapps/ee_live.tmp
mv 
/home/username/backup_webapps/ee_live.2 /home/username/backup_webapps/ee_live.3
mv 
/home/username/backup_webapps/ee_live.1 /home/username/backup_webapps/ee_live.2
mv 
/home/username/backup_webapps/ee_live.0 /home/username/backup_webapps/ee_live.1
mv 
/home/username/backup_webapps/ee_live.tmp /home/username/backup_webapps/ee_live.0
cp 
-al /home/username/backup_webapps/ee_live.1/. /home/username/backup_webapps/ee_live.0
rsync 
---delete /home/username/webapps/ee_live/ /home/username/backup_webapps/ee_live.0/

# Staging Site Snapshot
mv /home/username/backup_webapps/ee_stage.3 /home/username/backup_webapps/ee_stage.tmp
mv 
/home/username/backup_webapps/ee_stage.2 /home/username/backup_webapps/ee_stage.3
mv 
/home/username/backup_webapps/ee_stage.1 /home/username/backup_webapps/ee_stage.2
mv 
/home/username/backup_webapps/ee_stage.0 /home/username/backup_webapps/ee_stage.1
mv 
/home/username/backup_webapps/ee_stage.tmp /home/username/backup_webapps/ee_stage.0
cp 
-al /home/username/backup_webapps/ee_stage.1/. /home/username/backup_webapps/ee_stage.0
rsync 
---delete /home/username/webapps/ee_stage/ /home/username/backup_webapps/ee_stage.0

 

Cron runs every day at 3:01am:

#mysqlb_ee_stage and mysqlb_ee_live are duplicate instances of automysqlbackup.sh
1 3 * * * /home/username/bin/mysqlb_ee_stage.sh >> /dev/null 2>&1
1 3 
* * * /home/username/bin/mysqlb_ee_live.sh >> /dev/null 2>&1
1 3 
* * * /home/username/bin/webapps_backup.sh >> /dev/null 2>&

Category:Database Category:Tips

Category:EE1

Categories: