一个简单的SHELL备份脚本
实现:每周一对指定目录进行打包上传FTP,周二至周日做更新备份上传;
不妥之处请指教!
#!/bin/sh
backup_dir="/var/tmp/shell/"
DAT=`date | awk '{print $1}'`
if [ $DAT = 'Mon' ]
then
filename="`date +%G%m%d`.tar"
if [ -f $backup_dir$filename ]
then
rm -f $backup_dir$filename || echo "The backup is failure,please check" && exit
else
tar cvf $backup_dir$filename /var/tmp/tmp || echo "The backup is failure,please check" && exit
echo "Backup succeed"
fi
else
date=`date +%w`
aa=`expr $date - 1 `
bb="`date +%G%m%d`"
cc=`expr $bb - $aa`
filename="$cc.tar"
t1=`date +%d`
t2=`expr $t1 - 1 `
yesterday=`date +%Y\/%m\/`$t2
tar -N "$yesterday" -cvf $backup_dir$filename /var/tmp/tmp
echo "update"
fi
#ftp-put
host='x.x.x.x'
user='test'
passwd='pass'
mode='bin'
echo "Backup starting, please wait..."
ftp -i -n user $user $passwd
$mode
mput $filename
bye
!
echo "Backup finished"
阅读(558) | 评论(0) | 转发(0) |