sqlserver备份还原(解压上传到阿里云)

1.完全备份

mssql_backup.sh

#!/bin/bash
current_time=$(date "+%Y%m%d-%H%M%S")
backup_dir=‘/cygdrive/d/backup/‘
backup_zip_dir=‘/cygdrive/d/backup/Archive/‘
backup_archive_dir=‘/cygdrive/d/backup/Archive/‘
backup_cygwin_dir=${backup_archive_dir}${current_time}
backup_win_dir=‘d:\backup\Archive\‘${current_time}
backup_db=(WHQJAccountsDB WHQJAgentDB WHQJGameMatchDB WHQJGameScoreDB WHQJGroupDB WHQJNativeWebDB WHQJPlatformDB WHQJPlatformManagerDB WHQJRecordDB WHQJTreasureDB)
if [ ! -d ${backup_archive_dir} ]; then
mkdir -p ${backup_archive_dir} && chmod 777 ${backup_archive_dir}
fi
mkdir -p ${backup_cygwin_dir}
chmod 777 ${backup_cygwin_dir}
for element in ${backup_db[@]}
do
echo "backup "${element}
sqlcmd -S . -E -Q "BACKUP DATABASE ${element} TO DISK=‘${backup_win_dir}\\${element}.bak‘"
done
cd $backup_zip_dir
7z a ${current_time}.7z ${current_time} -sdel
./ossutil64 cp ${current_time}.7z oss://product-db-backup/test-mssql/

2.完全备份还原

mssql_restore.sh

#!/bin/bash
backup_dir="/cygdrive/d/backup11/backup11"
backup_win_dir="d:\\backup11\\backup11\\"
for sub_path in `ls ${backup_dir}`
do
database_name=`echo ${sub_path}|awk -F . ‘{print $1}‘`
echo "database_name is ${database_name}"
echo "bak name is ${sub_path}"
sqlcmd -S . -E -Q "RESTORE DATABASE ${database_name} FROM DISK=‘${backup_win_dir}${sub_path}‘"
if [ $? -eq 0 ];then
echo "succeful restore ${database_name}!!"
fi
sleep 5
done

3.差异备份

sql_server_diff_backup.sh

#!/bin/bash
backup_dir="/cygdrive/d/backup/diff"
backup_win_dir="d:\\backup\\diff"

sql_db=(WHQJAccountsDB WHQJAgentDB WHQJGameMatchDB WHQJGameScoreDB WHQJGroupDB WHQJNativeWebDB WHQJPlatformDB WHQJPlatformManagerDB WHQJRecordDB WHQJTreasureDB)
read -p "请输入你要恢复的库名(库名/all为所有库):" restore_db
read -p "请输入你要恢复到的目录数(file=?):" number
if [ ${restore_db} == "all" ];then
for i in ${sql_db[@]}
do
echo "##########开始恢复##########"
#备份结尾日志
sqlcmd -S . -E -Q "backup log ${i} to disk=‘d:\\backup\\diff\\${i}.bak‘ with norecovery"
for j in `seq ${number}`
do
if [ ${number} == ${j} ];then
sqlcmd -S . -E -Q "RESTORE database ${i} FROM DISK = ‘d:\\backup\\diff\\${i}.bak‘ WITH FILE=${j}, RECOVERY;"
else
sqlcmd -S . -E -Q "restore database ${i} from disk = ‘d:\\backup\\diff\\${i}.bak‘ with file=${j}, norecovery"
fi
done
done
else
if [ -f d:\\backup\\diff\\${restore_db}.bak ];then
sqlcmd -S . -E -Q "backup log ${restore_db} to disk=‘d:\\backup\\diff\\${restore_db}.bak‘ with norecovery"
for j in `seq ${number}`
do
if [ ${number} == ${j} ];then
sqlcmd -S . -E -Q "RESTORE database ${restore_db} FROM DISK = ‘d:\\backup\\diff\\${restore_db}.bak‘ WITH FILE=${j}, RECOVERY;"
else
sqlcmd -S . -E -Q "restore database ${restore_db} from disk = ‘d:\\backup\\diff\\${restore_db}.bak‘ with file=${j}, norecovery"
fi
done
else
echo "请输入正确的库名!"
fi
fi

4.差异备份还原

restore_diff_sqlserver.sh

#!/bin/bash
backup_dir="/cygdrive/d/backup/diff"
backup_win_dir="d:\\backup\\diff"
if [ ! -d ${backup_dir} ];then
mkdir ${backup_dir}
chmod 777 ${backup_dir}
fi

sql_db=(WHQJAccountsDB WHQJAgentDB WHQJGameMatchDB WHQJGameScoreDB WHQJGroupDB WHQJNativeWebDB WHQJPlatformDB WHQJPlatformManagerDB WHQJRecordDB WHQJTreasureDB)
for i in ${sql_db[@]}
do
if [ ! -f ${backup_win_dir}\\${i}.bak ];then
#第一次完全备份
sqlcmd -S . -E -Q "backup database ${i} to disk=‘d:\\backup\\diff\\${i}.bak‘ with init"
echo ""> d:\\backup\\diff\\file.txt
#在完:全备份基础上进行差异备份
else
sqlcmd -S . -E -Q "backup database ${i} to disk=‘d:\\backup\\diff\\${i}.bak‘ with differential"
fi
done

原文地址:https://www.cnblogs.com/leo001/p/12242433.html

时间: 2024-11-05 19:36:59

sqlserver备份还原(解压上传到阿里云)的相关文章

Docker之Alpine制作镜像且上传至阿里云

目的: Alpine制作jdk镜像 Alpine制作jre镜像(瘦身) Docker镜像上传至阿里云 Alpine制作jdk镜像 alpine Linux简介 Alpine Linux是一个轻型Linux发行版,它不同于通常的Linux发行版,Alpine采用了musl libc 和 BusyBox以减少系统的体积和运行时的资源消耗. alpine Linux优点 1.小巧:基于Musl libc和busybox,和busybox一样小巧,最小的Docker镜像只有5MB: 2.安全:面向安全的

Wordpress上传到阿里云服务器

Wordpress上传到阿里云服务器 登录服务器 https://account.aliyun.com/login/login.htm 绑定域名 获取FTP信息.数据库信息 在本地修改wordpress的配置文件wp-config.php 使用FileZilla上传网站文件到服务器 上传到htdocs目录 修改服务器数据库wp-option文件的网址链接,改成您的域名 注:此处不改的话进不了后台 访问域名 在浏览器中输入域名即可访问. 注:有时需要清除浏览器缓存,多次刷新清除尝试. GoodLu

Windows环境下用C#编程将文件上传至阿里云OSS笔记

本系列文章由ex_net(张建波)编写,转载请注明出处. http://blog.csdn.net/ex_net/article/details/24962567 作者:张建波 邮箱: [email protected]  欢迎来信交流! 第1步: 下载阿里云OSS的SDK包,由于笔者的环境是PHP服务,所以下载的是PHP的SDK包 http://help.aliyun.com/view/13438816.html 第2步:将代码整合进你的网站或服务中. 第3步:配置OSS访问接口 (1)找到c

文件上传到阿里云

/// <summary> /// 文件上传 /// </summary> /// <param name="file"></param> /// <param name="fileName"></param> /// <returns></returns> public string FileSaveAliyunOSS(HttpPostedFileBase file,

JavaScript进阶 九 JS实现本地文件上传至阿里云服务器

JS实现本地文件上传至阿里云服务器 前言 在前面的博客< JavaScript进阶(八)JS实现图片预览并导入服务器功能>(点击查看详情)中,实现了JS将本地图片文件预览并上传至阿里云服务器的操作.这次需要实现将本地打包好的文件上传至阿里云服务器.使用前面的图片文件上传方法无法完成此操作.操作界面如下: 思路 本地与服务端传输文件的格式应该是熟悉的Base64格式.首先需要将本地文件转换为Base64格式,传输至服务端后,在服务端再将Base64格式的文件转换为原始文件. 源码解析 控制器 /

Java下载https文件上传到阿里云oss服务

今天做了一个从Https链接中下载音频并且上传到OSS服务器,记录一下希望大家也少走弯路. 一共两个类: 1 实现自己的证书信任管理器类 /** * @author mazhq * @Title: X509TrustUtiil * @ProjectName: zeus * @Description: 证书信任管理器类 * @date 2019/2/18 15:14 */ public class X509TrustUtil implements X509TrustManager { @Overr

Java解压上传zip或rar文件,并解压遍历文件中的html的路径

1.本文只提供了一个功能的代码 public String addFreeMarker() throws Exception { HttpSession session = request.getSession(); User user = (User) session.getAttribute(Constant.USER_SESSION_KEY); String realName = user.getRealName(); System.out.println("--------获取登录用户信

解压上传的文本文件压缩包并将解压后的文本文件内容插入到数据库

$content = file_get_contents($_FILES["file"]["tmp_name"]); $ret->content = $content; if (file_exists("/var/www/api/uploads//" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"

linux本地远程上传&amp;下载阿里云oss的shell脚本实现方法

当项目早服务器中运行时会产生大量的日志,如果日志不处理全部放在本服务器中显然没有那么大的内存,除了要做必要的删除也要做日志必要备份. 创建oss.sh脚本: #!/bin/bash host="oss-cn-beijing.aliyuncs.com" bucket="****" ###bucket名字### Id="****************" ###Access ID### Key="******************&quo