Auto-snapshots / smart backup rentention

I ended up getting very specific with my backups. Maybe this can help someone else.

The way this works is that a monthly backup has weekly rolled into it, and a weekly backup has a daily backup rolled into it.

I’m using a Makefile:

build:
    @echo building includes...
    @rm -rf ${RESTIC_INCLUDE}/*
    @cp src/daily ${RESTIC_INCLUDE}/daily
    @cat src/daily src/weekly > ${RESTIC_INCLUDE}/weekly
    @cat src/daily src/weekly src/monthly > ${RESTIC_INCLUDE}/monthly

crontab:
    crontab -l | restic backup --stdin --tag crontab

daily: build
    restic backup --files-from ${RESTIC_INCLUDE}/daily --tag daily

weekly: build
    restic backup --files-from ${RESTIC_INCLUDE}/weekly --tag weekly

monthly: build
    restic-make
    restic backup --files-from ${RESTIC_INCLUDE}/monthly --tag monthly

forget:
    restic forget --keep-daily 7                 --tag daily -g tags
    restic forget                --keep-weekly 4 --tag weekly -g tags
    restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 -g tags


space:
    restic stats --mode raw-data

There’s a source directory that builds the files for daily, weekly, monthly and then the various backups are tagged as necessary.

$ ls $RESTIC_HOME/src/
daily  monthly  weekly

Then I run this via crontab:

15 0 * * *   make -C $RESTIC_HOME build daily
30 2 * * *   make -C $RESTIC_HOME forget
0  2 * * sun make -C $RESTIC_HOME build weekly
0  3 * * sun make -C $RESTIC_HOME prune
0  4 1 * *   make -C $RESTIC_HOME build monthly

The environmental variables being set are excluded. I actually set them in my shell. They can be set in the crontab, of course.

This keeps all monthly backups for 1 year, all weekly for 4 weeks, and all daily for 7 days. Since all the backups overlap, everything is backed up for one year.

I hope this helps someone else

1 Like