|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册账号
×
SQL自动备份
//////////////////////////每天更新/////////////////////////
DECLARE @file_name varchar(128)
set @file_name='E:\ERPDBBACKUP_Daily\ERPDB_'+ left(YEAR(GETDATE()),4)+'_'+left(month(GETDATE()),2)+'_'+left(day(GETDATE()),2)
BACKUP DATABASE ERPDB TO [email=disk=@file_name]disk=@file_name[/email] with format
RESTORE DATABASE TESTDB1 FROM [email=DISK=@file_name]DISK=@file_name[/email] WITH
MOVE 'XTQ_Data' TO 'D:\BACKUPDB\TESTDB1_DATA.mdf',
MOVE 'XTQ_Log' TO 'D:\BACKUPDB\TESTDB1_log.LDF'
////////////////////////每周更新//////////////////////////////
DECLARE @file_name varchar(128)
set @file_name='E:\ERPDBBACKUP_Week\ERPDB_'+ left(YEAR(GETDATE()),4)+'_'+left(month(GETDATE()),2)+'_'+left(day(GETDATE()),2)+'_W'
BACKUP DATABASE ERPDB TO [email=disk=@file_name]disk=@file_name[/email] with format
RESTORE DATABASE TESTDB2 FROM [email=DISK=@file_name]DISK=@file_name[/email] WITH
MOVE 'XTQ_Data' TO 'D:\BACKUPDB\TESTDB2_DATA.mdf',
MOVE 'XTQ_Log' TO 'D:\BACKUPDB\TESTDB2_log.LDF'
//////////////////////每月更新////////////////////////////////
DECLARE @file_name varchar(128)
set @file_name='E:\ERPDBBACKUP_Month\ERPDB_'+ left(YEAR(GETDATE()),4)+'_'+left(month(GETDATE()),2)+'_'+left(day(GETDATE()),2)+'_M'
BACKUP DATABASE ERPDB TO [email=disk=@file_name]disk=@file_name[/email] with format
RESTORE DATABASE TESTDB3 FROM [email=DISK=@file_name]DISK=@file_name[/email] WITH
MOVE 'XTQ_Data' TO 'D:\BACKUPDB\TESTDB3_DATA.mdf',
MOVE 'XTQ_Log' TO 'D:\BACKUPDB\TESTDB3_log.LDF' |
|