A wrapper around tarsnap which does two things:
- Lets you define "backup jobs" (tarsnap invocations) in a config file, though on it's own this has little advantage over just using a a shell script.
- The ability to expire old backups using a Grandfather-father-son backup scheme. This feature can be used in conjunction with tarsnapper backup jobs, or standalone, to be applied to any existing set of tarsnap backup archives, regardless of how they have been created.
$ apt-get install python-setuptools $ easy_install tarsnapper
Using a configuration file
A configuration file looks like this:
# Global values, valid for all jobs unless overridden: deltas: 1d 7d 30d target: /localmachine/$name-$date jobs: images: source: /var/lib/mysql exclude: /var/lib/mysql/temp exec_before: service stop mysql exec_after: service start mysql # Aliases can be used when renaming a job to match old archives. alias: img some-other-job: sources: - /var/dir/1 - /etc/google excludes: - /etc/google/cache target: /custom-target-$date.zip deltas: 1h 6h 1d 7d 24d 180d
images job, the global target will be used, with the
placeholder replaced by the backup job name, in this case
You can then ask tarsnapper to create new backups for each job:
$ tarsnapper -c myconfigfile make
The name of the archive will be the
target option, with the
placeholder replaced by the current timestamp, using either the
dateformat option, or
Or to expire those archives no longer needed, as per the chosen deltas:
$ tarsnapper -c myconfigfile expire
If you need to pass arguments through to tarsnap, you can do this as well:
$ tarsnapper -o configfile tarsnap.conf -o v -c tarsnapper.conf make
This will use
tarsnap.conf as the tarsnap configuration file,
tarsnapper.conf as the tarsnapper configuration file, and will also
put tarsnap into verbose mode via the
If you want to create the backups yourself, and are only interested in the expiration functionality, you can do just that:
$ tarsnapper --target "foobar-\$date" --deltas 1d 7d 30d - expire
--target argument selects which set of backups to apply the expire
operation to. All archives that match this expression are considered
to be part of the same backup set that you want to operate on.
tarsnapper will then look at the date of each archive (this is why
you need the
$date placeholder) and determine those which are not
needed to accomodate the given given delta range. It will parse the date
python-dateutil library, which supports a vast array of
different formats, though some restrictions apply: If you are using
yyyy-dd-mm, it cannot generally differentiate that from
You can specify a custom dateformat using the
which should be a format string as expected by the Python
%Y%m%d-%H%M%S). Usually, a custom format is not
Note the single "-" that needs to be given between the
argument and the command.
expire command supports a
--dry-run argument that will allow
you to see what would be deleted:
$ tarsnapper --target "foobar-\$date" --deltas 1d 7d 30d - expire --dry-run
How expiring backups works
The design goals for this were as follows:
- Do not require backup names to include information on which generation
a backup belongs to, like for example
tarsnap-generationsdoes. That is, you can create your backups anyway you wish, and simply use this utility to delete old backups.
- Do not use any fixed generations (weekly, monthly etc), but freeform timespans.
- Similarily, do not make any assumptions about when or if backup jobs have actually run or will run, but try to match the given deltas as closely as possible.
The generations are defined by a list of deltas.
60 means a minute,
12h is half a day,
7d is a week. The number of backups in each
generation is implied by it's and the parent generation's delta.
For example, given the deltas
1h 1d 7d, the first generation will
consist of 24 backups each one hour older than the previous (or the closest
approximation possible given the available backups), the second generation
of 7 backups each one day older than the previous, and backups older than
7 days will be discarded for good.
The most recent backup is always kept.
As an example, here is a list of backups from a Desktop computer that has
often been running non-stop for days, but also has on occasion been turned
off for weeks at a time, using the deltas
1d 7d 30d 360d 18000d:
dropbox-20140424-054252 dropbox-20140423-054120 dropbox-20140422-053921 dropbox-20140421-053920 dropbox-20140420-054246 dropbox-20140419-054007 dropbox-20140418-060211 dropbox-20140226-065032 dropbox-20140214-063824 dropbox-20140115-072109 dropbox-20131216-100926 dropbox-20131115-211256 dropbox-20131012-054438 dropbox-20130912-054731 dropbox-20130813-090621 dropbox-20130713-160422 dropbox-20130610-054348 dropbox-20130511-055537 dropbox-20130312-064042 dropbox-20120325-054505 dropbox-20110331-121745