当前位置:数据库 > SQLServer >>

mssql server 数据库备份语句

mssql server 数据库教程备份语句

declare @exec_str        varchar(60)
declare @exec_str_rar  varchar(60)
declare @exec_str_diff        varchar(60)
declare @exec_str_rar_diff  varchar(60)
declare @DEL_DATE_4   char(8)
select @DEL_DATE_4 = convert(char(8),DATEADD(dd,-4,GETDATE()),112)
--处理数据库 SZC   4天 带增备
select @exec_str      = 'del F:DB_BackXTOADB_FULL_' + @DEL_DATE_4 + '.bak'
select @exec_str_rar= 'del D:DB_Back_RARXTOADB_FULL_' + @DEL_DATE_4 + '.rar'
select @exec_str_diff      = 'del F:DB_BackdifferentXTOADB_DIFF_' + @DEL_DATE_4 + '*.bak'
select @exec_str_rar_diff= 'del D:DB_Back_RARdifferentXTOADB_DIFF_' + @DEL_DATE_4 + '*.rar'
exec master..xp_cmdshell @exec_str, no_output
exec master..xp_cmdshell @exec_str_rar, no_output
exec master..xp_cmdshell @exec_str_diff, no_output
exec master..xp_cmdshell @exec_str_rar_diff, no_output
--处理数据库 SZCStatistics  4天
select @exec_str      = 'del F:DB_BackXTOADBStatistics' + @DEL_DATE_4 + '.bak'
select @exec_str_rar= 'del D:DB_Back_RARXTOADBStatistics' + @DEL_DATE_4 + '.rar'
exec master..xp_cmdshell @exec_str, no_output
exec master..xp_cmdshell @exec_str_rar, no_output
--处理数据库 SZClog  4天
select @exec_str      = 'del F:DB_BackXTOADBlog' + @DEL_DATE_4 + '.bak'
select @exec_str_rar= 'del D:DB_Back_RARXTOADBlog' + @DEL_DATE_4 + '.rar'
exec master..xp_cmdshell @exec_str, no_output
exec master..xp_cmdshell @exec_str_rar, no_output
GO

--2. 步骤二:数据库备份处理

select '备份开始时间: ' = getdate()
declare @RCL_DATE char(8)
select @RCL_DATE = convert(char(8),GETDATE(),112)
declare @PATH varchar(60)
--数据库 SZC 的备份--带差异备份
select @PATH = 'F:DB_Back' + 'XTOADB_FULL_' + @RCL_DATE + '.bak'
BACKUP LOG XTOADB WITH TRUNCATE_ONLY
BACKUP DATABASE XTOADB TO DISK = @PATH WITH INIT
--数据库 SZCStatistics 的备份
select @PATH = 'F:DB_Back' + 'XTOADBStatistics' + @RCL_DATE + '.bak'
--BACKUP LOG XTOADBStatistics WITH TRUNCATE_ONLY
--BACKUP DATABASE XTOADBStatistics TO DISK = @PATH
--数据库 SZClog 的备份
select @PATH = 'F:DB_Back' + 'XTOADBlog' + @RCL_DATE + '.bak'
--BACKUP LOG XTOADBlog WITH TRUNCATE_ONLY
--BACKUP DATABASE XTOADBlog TO DISK = @PATH
GO?>

补充:数据库,Mssql
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,