Scheduling Backup Deletion with CRON
1. Open root's crontab
sudo crontab -e
2. Add a montly cron job
At the end of the doc add the following line:
0 5 1 * * /usr/local/bin/restic-cleanup.sh >> /var/log/restic-cleanup.log 2>&1
0 5- run at 5:001- on the 1st day of the month* *- every month, every weekday
NOTE: 2>&1 means "Send file descriptor 2 (errors) to the same place as file descriptor 1 (normal output)."
3. Make sure the enviroment is correct
Cron has a very limited PATH, so Restic might not be found unless it's set. Fortunately our restic_cleanup.sh script already contains the following line:
export PATH="/usr/bin:$PATH"
Optional: run it in dry-run mode once via cron
Instead add this line:
0 5 1 * * /usr/local/bin/restic-cleanup.sh dry-run >> /var/log/restic-cleanup.log 2>&1
Then after confirming logs look correct, change it to the real command.
4. Verify Cron installed the job
sudo crontab -l
You should see:
bash
0 5 1 * * /usr/local/bin/restic-cleanup.sh >> /var/log/restic-cleanup.log 2>&1