sql 備份
範例:
將以下這段存成 BackupScript.sql 的文字檔
-- 備份 master 資料庫
PRINT '《備份 master 資料庫》'
BACKUP DATABASE [master] TO DISK = N'C:\WaterLike\DB\master.bak' WITH NOFORMAT, INIT, NAME = N'master', SKIP, NOREWIND, NOUNLOAD, STATS = 10, CHECKSUM
GO
declare @backupSetId as int
select @backupSetId = position from msdb..backupset where database_name=N'master' and backup_set_id=(select max(backup_set_id) from msdb..backupset where database_name=N'master' )
if @backupSetId is null begin raiserror(N'確認失敗。找不到資料庫 ''master'' 的備份資訊。', 16, 1) end
RESTORE VERIFYONLY FROM DISK = N'C:\WaterLike\DB\master.bak' WITH FILE = @backupSetId, NOUNLOAD, NOREWIND
GO
將以下這段存成一個批次檔:
@PATH=C:\Program Files\Microsoft SQL Server\90\Tools\Binn;%CD%;
SQLCMD.exe -i BackupScript.sql -o BackupReport.txt
把他們放在相同的路徑下,然後電腦設一個排程定期去 RUN 批次檔就行了。