#!/bin/sh # HOWTO restic # 1. init repository # restic -r sftp:user@host:restic-repo init # 2. backup # restic -r /srv/restic-repo --verbose backup ~/work # 3. restore # restic -r /srv/restic-repo restore 79766175 --target /tmp/restore-work # list snapshots # restic -r /srv/restic-repo snapshots # filter by path # restic -r /srv/restic-repo snapshots --path="/srv" # integry check # restic -r /srv/restic-repo check # name of the temporary zfs snapshot. SNAPNAME="backup" # restic reads these, so we don't need the -r and -p parameters export RESTIC_PASSWORD_FILE="$HOME/.restic_password" export RESTIC_REPOSITORY="sftp:uugrn@uugrn.backup.haufe.it:uugrn-backup" # read the zfs snapshot list (takes some time) zfs list | cut -w -f1,5 | grep -v NAME | \ while read VOLUME do NAME=$(printf "$VOLUME" | cut -w -f1) MOUNTPOINT=$(printf "$VOLUME" | cut -w -f2) printf "\n%s\n%s\n" "# Snap: $NAME" "# Mountpoint: $MOUNTPOINT" # only backup mounted zfs volumes if [ "$MOUNTPOINT" == "none" ]; then printf "%s\n" "Volume $NAME not mounted. Not backing up." else # if a previous run did not clean up the snapshot, we do this now if [ -d "$MOUNTPOINT/.zfs/snapshot/$SNAPNAME" ]; then printf "%s\n" "Delete old snapshot" zfs destroy "$NAME@$SNAPNAME" fi # create zfs snapshot to freeze data for a moment printf "%s\n" "Create snapshot" zfs snap "$NAME@$SNAPNAME" # backup zfs snapshot directory with restic # (reason: does not need zfs to be restored) printf "%s\n" "Backup snapshot" restic backup "$MOUNTPOINT/.zfs/snapshot/$SNAPNAME/" --exclude-caches # delete the temporary zfs snapshot printf "%s\n" "Delete snapshot" zfs destroy "$NAME@$SNAPNAME" fi done # restic forgets "deletes" snapshots that do not match the specs # however it leaves the data alone. The data is now unreferenced, # but can still be used for deduplication. printf "\n%s\n" "Apply backup policy" restic forget --keep-daily=31 --keep-weekly=26 --keep-monthly=24 # restic prune needs to be called to cleanup the dereferenced blocks # and free up space. This is done in a separate script once a week. # list current list of restic snapshots (informational, not needed) printf "%s\n" "List restic snapshots" restic snapshots