Tuesday, February 09, 2016

attic prune when using a single repository for multiple hosts

I use Attic Backup.  I'm considering switching to the BorgBackup fork, but that'll be for the future.  Maybe when BorgBackup gets pull backups implemented.

I have multiple computers (some servers, some desktops/laptops).  All of them backup to the same attic repository.  This is mainly to take advantage of deduplication.  Some files are sufficiently important to me (and disk space is now sufficiently large) that I keep the important files synced on ALL my machines, servers, laptops and desktops alike.

The disk savings are pretty large and pretty obvious a reason for having just one backup repository.  There are disadvantages to this too.  Attic locks the repository when doing any work on it (including just listing the repository or showing information about individual archives).  So I have to schedule backups so that they don't interfere with each other.

Backups of the servers run fast enough (after the first 20+hour full backup) now that I can just set up their schedules 2 hours apart and be confident that the second won't need to wait in the queue for the first.  And if it has to, it's no big deal.

The laptops don't have daily backups (mainly because I haven't figured out yet how to get anacron to start up a backup when the laptop wakes up from suspend AND hasn't done a backup yet for that day).  I'll probably just run those backups once a week.  Or maybe I'll figure out how to get anacron to do it.

I also use

attic prune -v -d 30 -w 5 -m 12 -y 100 [REPOSITORY]

to prune old backups.  What this does is keep 30 daily backups, 5 weekly backups and so on.  The problem with this command line is that if I ran backups for server1, server2, laptop1, and laptop2 on the same day then only one of those backups will be kept.  Attic doesn't know which backups were for which servers.  It just knows which backups were done on which day, so it chooses one backup for the day and prunes/deletes the others.

The solution is to use the -p parameter.  -p [PREFIX] tells attic prune that it should ignore all backups except the ones that start with [PREFIX].  My backup archives are named, e.g.,

server1-2016-02-09

so in the scheduled shell script that runs the backup, before attic create runs, first attic prune runs:

 attic prune -v -d 30 -w 5 -m 12 -y 100 -p server1 [REPOSITORY]

This will consider only archives whose archive tag start with server1.  So archives for other servers and laptops are safe and are kept.  Only archives of the pattern server1* are considered for pruning according to the rules given on the command line.