异地备份SQL2005数据库
2010-05-21 10:55
218 查看
CREATE PROCEDURE [dbo].[backupDatabase]
AS
BEGIN
SET NOCOUNT ON;
---显示高级选项(仅需执行一次)
EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
---允许执行xp_cmdshell
EXEC sp_configure 'xp_cmdshell', 1
GO
RECONFIGURE
GO
---添加映射驱动器
declare @string nvarchar(200)
set @string = 'net use z: //172.16.1.222/Databasebackup "6141" /user:userqrlove\administrator'
exec master..xp_cmdshell @string
---其中172.16.1.222为文件服务器的地址,DatabaseBackup为该服务器的共享文件夹,userqrlove为机器名,administrator 6141 分别为共享时设置的用户名密码。
----备份数据库至本地
declare @date datetime
set @date = GetDate()
declare @str nvarchar(100)
set @str = 'd:\DatabaseBackup\hydee_syy_'+ convert(nvarchar(12), @date, 112) +'.bak'
backup database hydee_syy to disk=@str with init
---With init为覆盖同名文件(本例设计为1天执行一次,不会出现覆盖的情况)。
---拷贝到文件服务器
declare @str1 nvarchar(100)
set @str1 = 'copy '+ @str +' z:'
exec master..xp_cmdshell @str1
---删除映射以及本地备份
exec master..xp_cmdshell 'net use z: /delete'
declare @str2 nvarchar(100)
set @str2 = 'del '+@str+''
exec master..xp_cmdshell @str2
---关闭允许执行cmdshell
EXEC sp_configure 'xp_cmdshell', 0
GO
RECONFIGURE
GO
----成功备份
AS
BEGIN
SET NOCOUNT ON;
---显示高级选项(仅需执行一次)
EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
---允许执行xp_cmdshell
EXEC sp_configure 'xp_cmdshell', 1
GO
RECONFIGURE
GO
---添加映射驱动器
declare @string nvarchar(200)
set @string = 'net use z: //172.16.1.222/Databasebackup "6141" /user:userqrlove\administrator'
exec master..xp_cmdshell @string
---其中172.16.1.222为文件服务器的地址,DatabaseBackup为该服务器的共享文件夹,userqrlove为机器名,administrator 6141 分别为共享时设置的用户名密码。
----备份数据库至本地
declare @date datetime
set @date = GetDate()
declare @str nvarchar(100)
set @str = 'd:\DatabaseBackup\hydee_syy_'+ convert(nvarchar(12), @date, 112) +'.bak'
backup database hydee_syy to disk=@str with init
---With init为覆盖同名文件(本例设计为1天执行一次,不会出现覆盖的情况)。
---拷贝到文件服务器
declare @str1 nvarchar(100)
set @str1 = 'copy '+ @str +' z:'
exec master..xp_cmdshell @str1
---删除映射以及本地备份
exec master..xp_cmdshell 'net use z: /delete'
declare @str2 nvarchar(100)
set @str2 = 'del '+@str+''
exec master..xp_cmdshell @str2
---关闭允许执行cmdshell
EXEC sp_configure 'xp_cmdshell', 0
GO
RECONFIGURE
GO
----成功备份
相关文章推荐
- SQL2005数据库备份脚本[差异][完整][异地]
- 嘉兴市中级人民法院集中异地备份容灾及服务器虚拟化项目
- SQL server 2000异地备份
- sqlserver 异地备份
- 用复制命令做文件异地备份
- IBM的三种异地容灾备份方案
- [导入]用任务计划实现数据库的异地备份
- Navicat如何实现异地自动备份mysql数据库
- 本地和异地ftp传输备份脚本
- SQL Server 2005异地备份 - 转-已验证
- SQL Server 数据库实现异地备份
- VPS(网站数据+数据库)自动备份脚本(本地+ftp异地备份)
- rman如何直接备份到异地硬盘,磁带机和磁带库
- 使用SQL Server 2008数据库复制实现异地数据备份
- 通过vbs脚本备份数据-本地到异地
- SQL Server 2005异地备份
- 异地备份同步校验脚本
- 数据库Oracle数据的异地的自动备份
- 构建高安全电子商务网站之(网站文件及数据库自动本地/异地双备份)[连载之电子商务系统架构]
- mssql数据库异地备份的两种方法