Skip to content

Instantly share code, notes, and snippets.

@goyalankit
Created July 21, 2013 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goyalankit/6048984 to your computer and use it in GitHub Desktop.
Save goyalankit/6048984 to your computer and use it in GitHub Desktop.
#!/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