Introduce comprehensive recipes for Restic-based S3 backups. Covers installation, S3 repository configuration, automated backup job creation, and restoration of files.
115 lines
1.4 KiB
Markdown
115 lines
1.4 KiB
Markdown
# Create Automatic Backup Job
|
|
|
|
This recipe creates a daily backup job using Restic and systemd.
|
|
|
|
## Create Backup Script
|
|
|
|
```bash
|
|
sudo nano /usr/local/bin/restic-backup.sh
|
|
```
|
|
|
|
Contents:
|
|
|
|
```bash
|
|
#!/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
|
|
|
|
```bash
|
|
sudo chmod +x /usr/local/bin/restic-backup.sh
|
|
```
|
|
|
|
## Load Environment
|
|
|
|
```bash
|
|
source <(sudo cat /etc/restic.env)
|
|
```
|
|
|
|
## Test Backup
|
|
|
|
```bash
|
|
sudo /usr/local/bin/restic-backup.sh
|
|
```
|
|
|
|
## Verify Snapshot
|
|
|
|
```bash
|
|
restic snapshots
|
|
```
|
|
|
|
Expected output:
|
|
|
|
```text
|
|
ID Time Host
|
|
----------------------------------------
|
|
xxxxxxxx YYYY-MM-DD HH:MM hostname
|
|
```
|
|
|
|
## Automate with Cron
|
|
|
|
Edit root crontab.
|
|
|
|
```bash
|
|
sudo crontab -e
|
|
```
|
|
|
|
Add:
|
|
|
|
```cron
|
|
0 2 * * * /usr/local/bin/restic-backup.sh
|
|
```
|
|
|
|
## Verify Cron
|
|
|
|
```bash
|
|
sudo crontab -l
|
|
```
|
|
|
|
Expected output should contain:
|
|
|
|
```cron
|
|
0 2 * * * /usr/local/bin/restic-backup.sh
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
### Repository not found
|
|
|
|
Verify:
|
|
|
|
```bash
|
|
echo $RESTIC_REPOSITORY
|
|
```
|
|
|
|
### Authentication failed
|
|
|
|
Verify the configured S3 credentials.
|
|
|
|
```bash
|
|
echo $AWS_ACCESS_KEY_ID
|
|
```
|
|
|
|
```bash
|
|
echo $AWS_SECRET_ACCESS_KEY
|
|
```
|
|
|
|
### Wrong password
|
|
|
|
Verify:
|
|
|
|
```bash
|
|
echo $RESTIC_PASSWORD
|
|
```
|