Want to improve my simple site/db backup script with auto removal of old backups.
- by Robert Robb
I have the following simple script for backing up my website files and db. The script is run each day via a cron job.
#!/bin/sh
NOW=$(date +"%Y-%m-%d")
mysqldump --opt -h localhost -u username -p'password' dbname > /path/to/folder/backup/db-backup-$NOW.sql
gzip -f /path/to/folder/backup/db-backup-$NOW.sql
tar czf /path/to/folder/backup/web-backup-$NOW.tgz /path/to/folder/web/content/
It works great, but I don't want loads of old backups clogging my system. How can I modify the script to remove any backups older than a week when the script is run?