SqlServer自动作业备份 1、打开SQL Server Management Studio 2、启动SQL Server代理 3、点击作业->新建作业 4、”常规”中输入作业的名称 5、新建步骤,类型选T-
SqlServer自动作业备份
1、打开SQL Server Management Studio
2、启动SQL Server代理
3、点击作业->新建作业
4、”常规”中输入作业的名称
5、新建步骤,类型选T-SQL,在下面的命令中输入下面语句
复制代码代码如下:
DECLARE @strPath NVARCHAR(200)
set @strPath = convert(NVARCHAR(19),getdate(),120)
set @strPath = REPLACE(@strPath, ‘:’ , ‘.’)
set @strPath = ‘D:\bak\’ + ‘databasename’+@strPath + ‘.bak’
BACKUP DATABASE [databasename] TO DISK = @strPath WITH NOINIT , NOUNLOAD , NOSKIP , STATS = 10, NOFORMAT
set @strPath = convert(NVARCHAR(19),getdate(),120)
set @strPath = REPLACE(@strPath, ‘:’ , ‘.’)
set @strPath = ‘D:\bak\’ + ‘databasename’+@strPath + ‘.bak’
BACKUP DATABASE [databasename] TO DISK = @strPath WITH NOINIT , NOUNLOAD , NOSKIP , STATS = 10, NOFORMAT
例如:
DECLARE @strPath NVARCHAR(200)
set @strPath = convert(NVARCHAR(19),getdate(),120)
set @strPath = REPLACE(@strPath, ‘:’ , ‘.’)
set @strPath = ‘D:\bak\’ + ‘fx’+@strPath + ‘.bak’
BACKUP DATABASE [fx] TO DISK = @strPath WITH NOINIT , NOUNLOAD , NOSKIP , STATS = 10, NOFORMAT
set @strPath = convert(NVARCHAR(19),getdate(),120)
set @strPath = REPLACE(@strPath, ‘:’ , ‘.’)
set @strPath = ‘D:\bak\’ + ‘fx’+@strPath + ‘.bak’
BACKUP DATABASE [fx] TO DISK = @strPath WITH NOINIT , NOUNLOAD , NOSKIP , STATS = 10, NOFORMAT
(D:\bak\改为自己的备份路径,databasename修改为想备份的数据库的名称)
6、添加计划,设置频率,时间等。
评论前必须登录!
注册