Bash Script: Incremental Encrypted Backups with Duplicity (Amazon S3)

This bash script was designed to automate and simplify the remote backup process of duplicity on Amazon S3. After your script is configured, you can easily backup, restore, verify and clean (either via cron or manually) your data without having to remember lots of different command options and passphrases.

Most importantly, you can easily backup the script and your gpg key in a convenient passphrase-encrypted file. This comes in in handy if/when your machine ever does go belly up.

how to use

To get the bleeding edge very latest code in the script you can download a zip copy of the source or clone the git repository like so (a “stable” version 4 is coming soon):

  • git clone git://github.com/thornomad/dt-s3-backup.git

You’ll also need to have a number of things in place in order to utilize this script, specifically: gpg, duplicity, an Amazon S3 account, and (optionally) s3cmd. If you need help getting all these in order, I wrote another post about putting it all together. It’s not all that difficult, but does take a few pieces of the puzzle to be in order.

Once you have the script, you will need to fill out the foobar variables with your own specific information.  I suggest testing the script on a small directory of files and a local directory for your destination first to make sure it is working.

change log

Here is a list of the changes so far.

Version Four (March 2010)

  1. --list-files option
  2. --restore-file option
  3. --backup is a required option to actually run the script

Version Three (01/31/09)

  1. Added comment to explain why folks need to use s3+ and not s3: for Amazon buckets
  2. Used “unset” to remove the variables at end of the script (thanks: alvaro)
  3. Fixed a problem when the backup folder on S3 was nested inside another bucket (thanks John Kinsella)
  4. Changed the PASSPHRASE field to default to the actual passphrase, so one can easily backup the entire script and not have to worry about remembering the passphrase or where it’s kept.
  5. Added --backup-this-script option which will turn the script and the secret key into an encrypted tarball that can be kept somewhere safe for easy restores if the machine goes down.
  6. Cleaned up the get_file_size function so it wouldn’t run when it wasn’t supposed to.

Version Two (12/03/08) [Download Version 2]

  1. added GPL license
  2. changed the cleanup feature to automatically force a full backup after (n) number of days as well as automatically cleanup after (n) number of days
  3. added option to force cleanup after (n) number of full backups (rather than by days)
  4. option to changed log file ownership
  5. runtime checks for installed required software and write permissions on log directory
  6. fixed formatting of logfile to be a little more consistent
  7. setup everything in clever functions

Version One (11/24/08) [Download Version 1]

  1. Initial release.