網路上找來的,改了一點
==============================================
#!/bin/sh
backup_dir="/home/backup"
source_dir="/source"
MKDIR="$(which mkdir)"
TAR="$(which tar)"
MV="$(which mv)"
TODAY=`/bin/date +%Y%m%d`
test ! -d "$backup_dir/0/" && $MKDIR "$backup_dir/0/"
# tar zcv all file
$TAR zcPf "$backup_dir/0/source_$TODAY.tgz" $source_dir
# remove the oldest backup
test -d "$backup_dir/8/" && rm -rf "$backup_dir/8"
# rotate
for int in 7 6 5 4 3 2 1 0
do
if(test -d "$backup_dir"/"$int")
then
next_int=`expr $int + 1`
$MV "$backup_dir"/"$int" "$backup_dir"/"$next_int"
fi
done
exit 0;
沒有留言:
張貼留言