本文介绍了sql server数据库备份自动时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
这是Hem Raj Thakur,我想不时地自动创建数据库备份。
如何解决这个问题。请帮我。这是紧急的。
提前致谢。
Hem Raj Thakur
hi to all,
this is Hem Raj Thakur, and I want to create a database backup automatically time to time.
How can I solve this problems. please help me. It's Urgent.
Thanks in advance.
Hem Raj Thakur
推荐答案
DECLARE @name VARCHAR(50) -- database name
DECLARE @path VARCHAR(256) -- path for backup files
DECLARE @fileName VARCHAR(256) -- filename for backup
DECLARE @fileDate VARCHAR(20) -- used for file name
-- specify database backup directory
SET @path = 'C:\Backup\'
-- specify filename format
SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112)
DECLARE db_cursor CURSOR FOR
SELECT name
FROM master.dbo.sysdatabases
WHERE name NOT IN ('master','model','msdb','tempdb') -- exclude these databases
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @name
WHILE @@FETCH_STATUS = 0
BEGIN
SET @fileName = @path + @name + '_' + @fileDate + '.BAK'
BACKUP DATABASE @name TO DISK = @fileName
FETCH NEXT FROM db_cursor INTO @name
END
CLOSE db_cursor
DEALLOCATE db_cursor
2.在sql代理中按照规定的时间安排此过程。
或在任务计划程序中安排它如果您使用的是Express Edition
更多请参阅此
这篇关于sql server数据库备份自动时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!