每天需要把自己的工作目录备份一下,以备恢复,手动太麻烦了,写了
一个脚本如下
#根据日期和时间生成文件夹
DATE=`date +%Y%m%d`
TIME=`date +%H%M%S`
BAK_DIR=script.$DATE.$TIME
cd /home/myword
mkdir $BAK_DIR
mkdir $BAK_DIR/shell
mkdir $BAK_DIR/db
#备份还原数据库表
#db2 connect to switch
#db2 "export to './mytable.del' of del select * from schema.mytable";
#db2 "import from './mytable.del' of del insert_update into schema.mytable";
#db2 connect reset;
#备份源码和shell脚本
cp -r script $BAK_DIR
SCRIPT_FILES="/home/work/sbin/001.sh \
/home/work/sbin/002.sh \
/home/work/sbin/003.sh"
for FILE in $SCRIPT_FILES ; do
cp “$FILE" $BAK_DIR/shell
done
#打包并删除临时文件夹
tar -cf $BAK_DIR.tar $BAK_DIR
rm -rf $BAK_DIR
#通过ftp备份到其它机器
ftp -n -i <<!
open 192.168.0.21
user root 123456
cd /home/bak
bin
put $BAK_DIR.tar
bye
!