Want to improve my simple site/db backup script with auto removal of old backups.
Posted
by Robert Robb
on Stack Overflow
See other posts from Stack Overflow
or by Robert Robb
Published on 2010-03-21T00:52:24Z
Indexed on
2010/03/21
1:01 UTC
Read the original article
Hit count: 442
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?
© Stack Overflow or respective owner