Restic

Setup, for Backblaze

Create a configuration file:

cat > ~/.config/restic-backup.conf << 'EOF'
BACKUP_PATHS=/media/unencrypted_drive/SharedFolder
BACKUP_EXCLUDES='--exclude-caches --exclude /media/unencrypted_drive/SharedFolder/... --exclude /media/unencrypted_drive/SharedFolder/... --exclude "._*"'
RETENTION_DAYS=14
RETENTION_WEEKS=8
RETENTION_MONTHS=6
B2_ACCOUNT_ID=...
B2_ACCOUNT_KEY=...
RESTIC_REPOSITORY=b2:restic-personal-backup-1:home-hard-drive
RESTIC_PASSWORD=...
EOF

To source these as environment variables, simply do:

set -a
source ~/.config/restic-backup.conf

set +a # To unset.

Setup:

restic init

mkdir -p ~/.config/systemd/user/

cat > ~/.config/systemd/user/restic-backup.service << 'EOF'
[Unit]
Description=Restic backup service
[Service]
Type=oneshot
ExecStart=restic backup --verbose $BACKUP_EXCLUDES $BACKUP_PATHS
ExecStartPost=restic forget --verbose --keep-daily $RETENTION_DAYS --keep-weekly $RETENTION_WEEKS --keep-monthly $RETENTION_MONTHS --prune
EnvironmentFile=%h/.config/restic-backup.conf
EOF

cat > ~/.config/systemd/user/restic-backup.timer << 'EOF'
[Unit]
Description=Backup with restic daily
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
EOF

systemctl --user daemon-reload
systemctl --user enable --now restic-backup.timer

Then:

# Test once
systemctl --user start restic-backup

Other commands

# List snapshots
restic snapshots

# List files in 'latest' snapshot
restic ls latest "/media/unencrypted_drive/SharedFolder/"

# Restore a particular directory from 'latest' snapshot
restic restore latest --include "/media/unencrypted_drive/SharedFolder/Pictures" --target /tmp