linux下Sql server 数据库备份shell脚本
#/bin/bash yonghu=sa mima=woshimima back_path=/var/opt/mssql/data/ db_name=demo 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 /opt/mssql-tools/bin/sqlcmd -S localhost -U $yonghu -P $mima -d master -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