Am not entirely sure how to do this due to my lack of shell knowledge.
NOW=$(date +"%Y.%m.%d.%T")
tar czf /backups/web_backup_$NOW.tgz /web/
Can you please assist me to delete old backups so that it only keeps:
- Last 3 days
- One backup each from last 3 weeks
- One backup each for last 3 months
Look at rsnapshot. It might do what you want out of the box.
If you use rsnapshot in the first place, it performs proper backup retention on the fly (it creates that structure of hourly, daily, weekly, ... snapshots for you).
If you do not create snapshots with rsnapshot or already have a considerably large set of snapshots and want to thin it out in hindsight, then have a look at timegaps. It is designed exactly this use case (simple implementation of backup retention policies). According to your use case, you could invoke timegaps like that:
It would then identify those tgz files that need to be rejected (based on file modification time) and write those to stdout for review or further processing (non-invasive read-only mode). Timegaps can also
--move
these files or directlyor--delete
them. If required, it can parse the item creation time from the file name (have a look at the help message) instead of retrieving it viastat()
.Disclaimer: I am the author of timegaps.
something like this: (just an idea)