Home > Apache, Linux > lamp-backup :: Backing up LAMP Server Content

lamp-backup :: Backing up LAMP Server Content

February 28th, 2012 Leave a comment Go to comments

It’s been a while since I posted anything useful, but hopefully this will make up for it.

A friend came to me asking for help configuring the backup of his remote LAMP server and I duly obliged, but ended up getting a little carried away. Some hours later I emerged with this bash script to do the job properly.

Called from cron, each time the script runs:

  • It creates/updates a local rsync-copy of a remote directory.
  • It runs a mysqldump to a file, named by date-stamp.
  • Any archives or log files older than the user-specified expiry time (days) are deleted.
  • All three operations are carefully logged to appropriate “.log” and “.err” files.
  • The mysqldump, the rsync-copy and all the logs are run through tar.
  • The tarball is run through a user-specified compression program (default: xz).
  • The final archive is named by date-stamp.
  • A summary file is created including highlighted errors and execution times for each step.
  • The summary.log is (optionally) e-mailed to the backup administrator.
  • The script cleans up after itself, deleting any superfluous log and mysqldump files.

In the end you have a configurable period of snapshotted-history for your LAMP server, all in small archive files, named by their date and with logs for every step of every backup and permanently-deleted file.

I recommend the script is called by cron like this (assuming midnight backup):

0 * * * * /path/to/lamp-backup.sh 1>/path/to/lamp-backup/lamp-backup.log 2>/path/to/lamp-backup.err

Which will also give you activity and error logs for the script itself.

If you wish to run the script manually from the command line to test it, you can set the output to verbose like this:

$ VERBOSE=true ./lamp-backup.sh

Ensure that lamp-backup.conf lives in the same directory as lamp-backup.sh and is readable and carefully configured.


You can get a copy of v1.0 (stable) of this script and associated config file from my subversion repository:


I will be working on it more soon, abstracting further, adding command line parameters and adding additional features that seem useful.

You can track the current version via the repository trunk.

Be Sociable, Share!
Categories: Apache, Linux Tags: , , , , ,
  1. No comments yet.
  1. No trackbacks yet.

Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).