Created
June 4, 2024 13:21
-
-
Save foreignmeloman/e0729fc9c6f2e15d323ac95f42b82996 to your computer and use it in GitHub Desktop.
A boilerplate shell code to implement restic backups with S3-compatible backend.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| export RESTIC_REPOSITORY="s3:https://url.to/s3/compatible/bucket" | |
| export RESTIC_PASSWORD="RESTIC_PASSWORD" | |
| export AWS_ACCESS_KEY_ID="AWS_ACCESS_KEY_ID" | |
| export AWS_SECRET_ACCESS_KEY="AWS_SECRET_ACCESS_KEY" | |
| # Automatically initialize restic repo if it does not exist | |
| status="$(restic cat config 2>&1)" | |
| if [ $? -ne 0 ]; then | |
| if echo $status | grep -qF "Fatal: unable to open config file: Stat: The specified key does not exist."; then | |
| restic init | |
| else | |
| restic cat config | |
| exit 1 | |
| fi | |
| fi | |
| # Perform the backup | |
| restic backup \ | |
| --exclude /paths/to/backup/ignore \ | |
| /paths/to/backup | |
| # Clenup the old snapshots | |
| restic forget --keep-daily=7 --keep-weekly=4 --keep-monthly=3 --prune | |
| # Verify the data integrity | |
| restic check --read-data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment