sqlserver备份和恢复-5

时间:2022-08-02 14:03:56

视图备份和恢复

备份

1.

sqlserver备份和恢复-5

2.

sqlserver备份和恢复-5

恢复

1.

sqlserver备份和恢复-5 

2.

sqlserver备份和恢复-5

3.勾选覆盖现有数据库。

sqlserver备份和恢复-5

4.

sqlserver备份和恢复-5

 

bat备份恢复

原文:

https://www.cnblogs.com/lonelyxmas/p/7958649.html

备份:(注意*.sql要写绝对路径不然计划任务不执行)

sqlserverbackup.bat
--------------------------------------
@echo off
set path=%path%;D:\Program Files\Microsoft SQL Server\100\Tools\Binn
set BakDir='D:\backup\sqlserver'
echo backup start
osql.exe -S 127.0.0.1 -U sa -P xxxxxx -i Test_ReportV3backup.sql -o D:\backup\sqlserver\Test_ReportV3backup.out
osql.exe -S 127.0.0.1 -U sa -P xxxxxx -i West_Report(Bata)backup.sql -o D:\backup\sqlserver\West_Report(Bata)backup.out
osql.exe -S 127.0.0.1 -U sa -P xxxxxx -i West_TestReportbackup.sql -o D:\backup\sqlserver\West_TestReportbackup.out
forfiles /p %BakDir% /s /m *.* /d -10 /c "cmd /c del @file"
echo backup end
---------------------------------------

*.sql
---------------------------------------
DECLARE @name varchar(50)
DECLARE @datetime char(14)
DECLARE @path varchar(255)
DECLARE @bakfile varchar(255)

set @datetime=CONVERT(char(8),getdate(),112) + REPLACE(CONVERT(char(8),getdate(),108),':','')
set @path='D:\backup\sqlserver\'
set @name='Test_ReportV3'
set @bakfile=@path+''+@name+'_'+'bak_'+@datetime+'.BAK'
backup database @name to disk=@bakfile with name=@name
go
---------------------------------------

 恢复

请看原文