Feb 232014
 

I’ve been using this shell script to backup my WordPress site and database for a while. There is nothing WordPress-specific in it though, the script can be used for anything that uses a database. It creates a MySQL dump of the database and a ‘ls’ of the site directory, compares then to the last ones and creates a new archives of each of them if something has changed. What it doesn’t do is move those files off-site for an actual backup.

Works for small sites, like this one. Dumping the whole database just to see if anything changed might become an incresingly worse idea as the site grows. Use common sense, run on a slave for bigger setups or something.

It is very incomplete, just a skeleton. I was planning to improve it, but since it’s good enough for my needs I seem to never find the time to do it.

If anything changed since the last backup it will set the variables $DBCHANGED and $WWWCHANGED to "YES". Lines 79-92 check those variables and act accordingly. This is where code to move the backups off-server could be added. Incremental backups could also be implemented by using diff(1) to create patch files instead of archiving the whole thing every time.

A few ideas for moving the files to another server include using something like Dropbox or Google Drive, uploading the files via FTP or similar, sending them by mail as attachement using mutt, backing them up on a VCS like svn or git, copying to a shared directory for a different server to pull them.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

(required)

(required)