Created
July 21, 2013 16:13
-
-
Save goyalankit/6048984 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
#!/bin/sh | |
function keep_only_last_for_n_days_ago(){ | |
echo "function called with $1" | |
CDIR=`date +%y%m%d -d "$1 day ago"` | |
count=0 | |
for j in `ls -1t "$CDIR"` | |
do | |
count=`expr $count + 1` | |
if [ $count == 1 ] | |
then | |
echo "Not deleting $j" | |
continue | |
fi | |
echo "Deleting $j" | |
rm "$CDIR/$j" | |
done | |
} | |
# | |
# Keeping only one file for last week for each day. The last backup on that particular day. | |
# | |
for i in {7..30} | |
do | |
keep_only_last_for_n_days_ago $i | |
done | |
#Keeping only weekend file | |
for k in {30..50} | |
do | |
CDIRDAY=`date +%A -d "$k day ago"` | |
CDIR=`date +%y%m%d -d "$k day ago"` | |
if [ $CDIRDAY == "Sunday" ] | |
then | |
echo "it's sunday" | |
keep_only_last_for_n_days_ago $k | |
continue | |
fi | |
echo "it's not a sunday its $CDIRDAY on $CDIR" | |
rm -rf "$CDIR" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment