Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

73 lines (61 sloc) 3.212 kb




Cycles Tarsnap backups in a grandfather-father-son scheme.


The script is designed to be run via crontab or equivalent.

             ?   Display this help.    
            -f   Path to a file with a list of folders to be backed up. List should be newline delimited.  
            -h   Number of hourly backups to retain.
            -d   Number of daily backups to retain.
            -w   Number of weekly backups to retain.
            -m   Number of monthly backups to retain.
            -q   Be quiet - limits output unless something goes wrong.


The script is designed to be run via crontab. It expects five inputs and a working Tarsnap configuration file (see below). If you don't want to take hourly backups then use cron to schedule a backup only in the hour specified in the script as the $DAILY_TIME variable, line 9. Set -h to "1". By default the script takes the "DAILY" backup in the 23:00 hour system time.


The tarsnap-generations requires a .tarsnaprc or tarsnap.conf that specifies at least these options -

    keyfile <path to keyfile>  
    cachedir <path to cache dir>  
    exclude <path to cache dir>  

See the Tarsnap documentation for more details.


    15 * * * * -f /root/tarsnap.folders -h 36 -d 30 -w 12 -m 24

Takes a backup every hour at the :15, keeps 36 hours of hourly backups, 30 days of daily backups, 12 weeks of weekly backups and 2 years of monthly backups.

    30 23 * * * -f /root/tarsnap.folders -h 1 -d 10 -w 4 -m 2

No hourly backups, a daily backup at 23:30, keeps 10 days of daily backups, 4 weeks of weekly backups and 2 months of monthly backups. Note that the hour here (23) must match the hour set by $DAILY_TIME, line 9 of the script. 23 (11PM) is the default.


The script will exit with a non 0 error code if a backup fails or can't be verified. Be sure to pay attention.


Tarsnap needs to be working properly for tarsnap-generations to work. To quickly test if Tarsnap is working -

    $ tarsnap -c -f test-backup-1 /sbin    # This will take a backup of the /sbin directory.

If there are no errors then let's make sure the archive was created -

    $ tarsnap --list-archives    # This will list all of the existing backups. 
    test-backup-1    # If the backup we just created is listed then Tarsnap is woring properly.

If any of those steps failed see the Tarsnap getting started documentation for help.

Be sure to delete the test backup, you are being charged for it!

    $ tarsnap -d -f test-backup-1



Jump to Line
Something went wrong with that request. Please try again.