Skip to content

Instantly share code, notes, and snippets.

@stanwu
Created July 17, 2012 17:56
Show Gist options
  • Save stanwu/3130846 to your computer and use it in GitHub Desktop.
Save stanwu/3130846 to your computer and use it in GitHub Desktop.
auto backup folder (if less then 8GB total space)
#!/bin/bash
for i in `ls`
do
#echo "[$i]"
if [ -d $i ]; then
mysize=`du -d 0 $i | awk '{print $1}'`
mydate=`date +%m%d%y`
if [ $mysize -lt 8388608 ]; then
echo "Pack $i -> $mysize"
tar cvzf $i.$mydate.$mysize.tgz $i
if [ $? == 0 ]; then
echo "OK!"
rm -rf $i
else
echo "Err!"
rm $i.$mydate.$mysize.tgz
fi
else
echo "Skip $i -> $mysie (too large)"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment