2014年12月18日 星期四

SQL Server 維護計畫 (完整備份)

SQL Server 維護計畫 (完整備份)
(EX: test_DB)
因為在 SQL Server 維護計畫中,
產生備份檔案時,無法設定檔案的名稱格式,

故自行撰寫  T-SQL 的備份指令,
並依自己喜好,設定檔案的名稱格式

1.test_DB_full_backup (test_DB_完整備份)
執行 T-SQL 陳述式_完整備份
-- T-SQL 陳述式:
declare @rec_time Nvarchar(19)
declare @filename Nvarchar(100)
declare @save_to Nvarchar(200)
set @rec_time = convert(char(19),getdate(),120)
set @rec_time = REPLACE(@rec_time, ':', '')
set @rec_time = REPLACE(@rec_time, '-', '')
set @rec_time = REPLACE(@rec_time, ' ', '_')
set @filename = N'test_DB_Full_Backup_' + @rec_time
set @save_to = N'C:\test\MSSQL\Backup\test_DB\' +@filename +N'.bak'
print @save_to
BACKUP DATABASE [test_DB] TO DISK = @save_to WITH NOFORMAT, INIT,   NAME = @filename, SKIP, REWIND, NOUNLOAD, COMPRESSION,  STATS = 10


2.test_DB_Trans_backup (test_DB_交易紀錄備份)
執行 T-SQL 陳述式_交易紀錄備份
-- T-SQL 陳述式:
declare @rec_time Nvarchar(19)
declare @filename Nvarchar(100)
declare @save_to Nvarchar(200)
set @rec_time = convert(char(19),getdate(),120)
set @rec_time = REPLACE(@rec_time, ':', '')
set @rec_time = REPLACE(@rec_time, '-', '')
set @rec_time = REPLACE(@rec_time, ' ', '_')
set @filename = N'test_DB_Trans_Log_' + @rec_time
set @save_to = N'C:\test\MSSQL\Backup\test_DB\' +@filename +N'.trn'
print @save_to
BACKUP LOG [test_DB] TO  DISK = @save_to WITH NOFORMAT, NOINIT,  NAME = @filename, SKIP, REWIND, NOUNLOAD, COMPRESSION,  STATS = 10


使用方式:
在維護計畫的工具箱中,
選擇 "執行 T-SQL 陳述式工作"


加到子計畫中,並且對其連點兩下,
進入編輯畫面,輸入自行撰寫的陳述式即可


註:在 T-SQL 陳述式 中的備份指令,是參考工具箱中 "備份資料庫工作" 的設定而來。


1 則留言:

  1. How to get to Kambi Casino in Thangorn by Bus - JtmHub
    With Kambi Casino in 동두천 출장안마 Thangorn 평택 출장안마 you 강릉 출장마사지 will 제천 출장마사지 find an easy to reach area that features free betting, live casino, and gaming. All you need to 부천 출장샵 do is

    回覆刪除