主机备份脚本
#/bin/bash
user=sa
passwd=123456
back_path=/home/shell/
db_name=testdb
back_time=`date +%Y%m%d_%H%M%S`
back_filename=$back_path$db_name$back_time
del_time=`date -d "2 day ago" +"%Y%m%d"`
del_backfile=$back_path$db_name$del_time
sqlcmd -S localhost -U $user -P $passwd -d $db_name -Q "BACKUP DATABASE $db_name to disk='$back_filename.bak'"
tar -zcPf $back_filename.tar.gz $back_filename.bak
rm -f $back_filename.bak
if [ -e $back_filename.tar.gz ];then
rm -rf $del_backfile*.gz
echo "database[multiverse] backup success! "
else
echo "database[multiverse] backup failed!"
fi
异地备份拷贝脚本
#!/usr/bin/expect -f
#!/bin/sh
set passwd "123456"
set DATE [exec date +%Y%m%d]
spawn scp root@192.168.10.100:/home/shell/*$DATE*.tar.gz /home/test_DB_BAK
expect {
"pass"
{
send "$passwd\n"
}
"yes/no"
{
sleep 5
send_user "send yes"
send "yes\n"
}
eof
{
sleep 5
send_user "eof\n"
}
}
set timeout 3000
send "exit\r"
expect eof
注意点:
1.执行脚本文件夹有可访问权限,通过chmod命令赋权限。
2.两台机器需有scp,spawn命令。
3.两台机器在同一个网段,网络畅通。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)