#!/bin/sh set -eu backup_keep=1m main() { # remove stale locks resticw unlock || : # run backup resticw backup \ --skip-if-unchanged \ --files-from "/usr/share/resticbackup/includes" \ --files-from "/etc/resticbackup/includes" \ --exclude-file "/usr/share/resticbackup/excludes" \ --exclude-file "/etc/resticbackup/excludes" \ --tag resticbackup # prune backups older than $backup_keep duration resticw forget \ --keep-within "${backup_keep}" \ --prune \ --group-by "paths,tags" \ --tag resticbackup resticw check # TODO: dump stats to file in metrics format to /run/prom/restic } exit_hook() { # shellcheck disable=3043 local rc=$? resticw unlock || : if [ "$rc" = 0 ]; then logger --id=$$ --msgid=BACKUPEND --priority=notice "backup finished" else logger --id=$$ --msgid=BACKUPEND --priority=error "backup failed" fi } trap exit_hook INT EXIT logger --id=$$ --msgid=BACKUPSTART --priority=notice "backup starting..." main >>"/var/log/resticbackup.log" 2>&1