Creating a Backup Script

Introduction

This document describes how you might create a simple backup script which gets run automatically via a cron job. Note that it keeps the backup on the same machine as the files that it is protecting, so it is no good against disk failures! Consider using rsync> to your home machine or see the Shack Wiki for more ideas.

Creating the Script

None of this needs to be done by root (and is better not!) Start by creating a directory to hold the script and one to hold the backup files:

Now start your favourite text editor (vi, emacs, etc, not a word-processor...) and paste in the following script:

Save it as 'do-backup' and exit from the editor. Now make the script executable:

Check that the script is syntactically correct:

Now try running it:

If that works you should get a file created in the ~/backups directory.

Automating the Backup

To automate the process you need to get cron to run the script each night:

This will start an editor. Paste in this line:

Be careful not to leave any blank lines in the file. Write the file back and exit from the editor. Cron will now run your script every night at 03:05. Wait a day, and check that another backup file has appeared.

Remember that the backups directory will grow forever unless you uncomment the cleanup line in the script.