Files
.profile/recipes/backup/03_create-backup-job.md
JotaOdiceu 6cf5a08187 feat(backup): add Restic S3 backup recipes
Introduce comprehensive recipes for Restic-based S3 backups.
Covers installation, S3 repository configuration, automated backup job creation, and restoration of files.
2026-07-04 19:26:01 -03:00

1.4 KiB

Create Automatic Backup Job

This recipe creates a daily backup job using Restic and systemd.

Create Backup Script

sudo nano /usr/local/bin/restic-backup.sh

Contents:

#!/usr/bin/env bash
set -e

source /etc/restic.env

restic backup <PATH>

restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --keep-yearly 3 --prune

Replace:

  • <PATH> with the folder path you want to backup (e.g. /srv/samba)

Make Script Executable

sudo chmod +x /usr/local/bin/restic-backup.sh

Load Environment

source <(sudo cat /etc/restic.env)

Test Backup

sudo /usr/local/bin/restic-backup.sh

Verify Snapshot

restic snapshots

Expected output:

ID        Time                 Host
----------------------------------------
xxxxxxxx  YYYY-MM-DD HH:MM     hostname

Automate with Cron

Edit root crontab.

sudo crontab -e

Add:

0 2 * * * /usr/local/bin/restic-backup.sh

Verify Cron

sudo crontab -l

Expected output should contain:

0 2 * * * /usr/local/bin/restic-backup.sh

Troubleshooting

Repository not found

Verify:

echo $RESTIC_REPOSITORY

Authentication failed

Verify the configured S3 credentials.

echo $AWS_ACCESS_KEY_ID
echo $AWS_SECRET_ACCESS_KEY

Wrong password

Verify:

echo $RESTIC_PASSWORD