Created
July 28, 2014 18:17
-
-
Save sbryant/de93ae53c379b196a332 to your computer and use it in GitHub Desktop.
This file contains 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
prune_old_backups() { | |
[ -n "$backups_to_keep" ] || return | |
local num_re="[0-9]+" | |
[ "$backups_to_keep" =~ "$num_re" ] || { echo "Backups to keep needs to be a number"; return } | |
num_of_backups=$(ls -l "$backup_dir" | wc -l) | |
if [ "$num_of_backups" > "$backups_to_keep" ]; then | |
echo "Pruning backups" | |
dirs_to_remove=$(ls -t | awk "NR>$backups_to_keep") | |
echo "would remove $dirs_to_remove" | |
echo "echo $dir_to_remove | xargs rm -rf" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment