#!/bin/sh # HOWTO restic # 1a. init repository (sftp backend) # restic -r sftp:user@host:restic-repo init # 1b. init repository (local backend) # restic -r /srv/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 # snapshot deletion policy # restic -r /srv/restic-repo forget -d 31 -w 26 -m 24 # clean up unreferenced blocks # restic -r /srv/restic-repo prune # 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) # only backup mounted zfs volumes if [ "$MOUNTPOINT" == "none" ]; then printf "%s\n" "Volume $NAME not mounted. Not backing up." else # Listing and searching for a snaptshot takes MUCH longer than # simply trying to delete it. printf "%s\n" "Delete Leftover Snapshot: $NAME@$SNAPNAME" zfs destroy "$NAME@$SNAPNAME" # create zfs snapshot to freeze data for a moment printf "%s\n" "Creating Snapshot: $NAME@$SNAPNAME" zfs snap "$NAME@$SNAPNAME" # backup zfs snapshot directory with restic # (reason: does not need zfs to be restored) printf "%s\n" "Transferring Snapshot: $NAME@$SNAPNAME" restic backup "$MOUNTPOINT/.zfs/snapshot/$SNAPNAME/" --exclude-caches || exit # delete the temporary zfs snapshot printf "%s\n" "Deleting Snapshot: $NAME@$SNAPNAME" zfs destroy "$NAME@$SNAPNAME" fi done # restic forget "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 "%s\n" "Dereference Outdated Backups:" restic forget --keep-daily=31 --keep-weekly=26 --keep-monthly=24 # restic prune cleans up the unreferenced data and therefore frees # up space on the backup device printf "%s\n" "Prune Backups:" restic prune # list current list of restic snapshots (informational, not needed) printf "%s\n" "List Restic Backups:" restic snapshots