Restic

Restic is a backup program for Linux that can take backups to various storage providers. I am using it with Backblaze B2.

Setting up

In summary:

  1. Create an application password in B2 and note down the keyID and key

  2. Create a bucket using restic by running

    export B2_ACCOUNT_ID=<application key ID>
    export B2_ACCOUNT_KEY=<application key>
    restic -r b2:<bucket name>:/ init
    
  3. You can now create snapshots by running

    restic -r b2:<bucket name>:/ backup <...paths>
    
  4. Automate it with a systemd timer

    • ~/.config/restic/restic.conf
      BACKUP_PATHS="/home/mpardalos/Documents /home/mpardalos/Pictures"
      BACKUP_EXCLUDES="--exclude-file /home/mpardalos/.config/restic/excludes --exclude-if-present .exclude_from_backup"
      RETENTION_DAYS=7
      RETENTION_WEEKS=4
      RETENTION_MONTHS=6
      RETENTION_YEARS=3
      B2_ACCOUNT_ID=...
      B2_ACCOUNT_KEY=...
      RESTIC_REPOSITORY=...
      RESTIC_PASSWORD=...
      
    • ~/.config/restic/excludes Excludes go here. If none, create it and leave it empty.
    • ~/.config/systemd/user/restic-backup.service
      [Unit]
      Description=Restic backup service
      [Service]
      Type=oneshot
      ExecStart=restic backup --verbose --one-file-system --tag systemd.timer $BACKUP_EXCLUDES $BACKUP_PATHS
      ExecStartPost=restic forget --verbose --tag systemd.timer --group-by "paths,tags" --keep-daily $RETENTION_DAYS --keep-weekly $RETENTION_WEEKS --keep-monthly $RETENTION_MONTHS --keep-yearly $RETENTION_YEARS
      EnvironmentFile=%h/.config/restic/restic.conf
      
    • ~/.config/systemd/user/restic-backup.timer
      [Unit]
      Description=Backup with restic daily
      [Timer]
      OnCalendar=daily
      Persistent=true
      [Install]
      WantedBy=timers.target
      

    Just enable the timer and everything should be set systemctl --user enable --now restic-backup.timer