Created
January 29, 2014 10:03
-
-
Save Korko/8684951 to your computer and use it in GitHub Desktop.
Keep hourly backups and only keep some of them for each day etc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Warning, for each of these rules, we keep the oldest ones | |
# this is required in order to have some files in the oher category | |
KEEP_DAY=1 # How many to keep for each day (except for the current 24h and more than a week) | |
KEEP_WEEK=0 # How many to keep over a week old | |
for i in {1..6} ; do | |
# Find all files that are older than $i days and younger than ($i+1) days and remove them | |
find . -mtime $i -mtime -$(($i+1)) | sort | tail -n +$(($KEEP_DAY+1)) | xargs rm -Rf | |
done | |
find . -mtime +6 | sort | tail -n +$(($KEEP_WEEK+1)) | xargs rm -Rf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment