打开企业管理器,展开你的SQL Server服务实例,看到“管理”没有?展开“管理”,看到“作业”没有,右键单击它选择“新建作业”,写写代码就行了!
--Perform Full BackUp
Declare @FullFileName Varchar(200)
Declare @FileFlag varchar(20)
Set @FileFlag=convert(char(8),getdate(),112)
Set @FullFileName=''D:\BackUp\MIS\MIS_FULL''+@FileFlag+''.BAK''
--完整备份,文件名 MIS_FULL20060831.BAK
BackUp DataBase MIS To Disk=@FullFileName with init
Go
--拷贝到远程电脑上
exec master..xp_cmdshell ''net use \\192.168.0.10\d$ password /user:domain\administrator''
Go
--Copy backup file to remote server
Declare @BKFileName varchar(200)
Declare @DestFileName varchar(200)
Declare @FileFlag varchar(8)
Declare @SQLStr varchar(300)
Set @FileFlag=convert(char(8),getdate(),112)
Set @BkFileName=''D:\backup\MIS\MIS_FULL''+@FileFlag+''.BAK''
Set @DestFileName=''\\192.168.0.10\d$\BackUp\MIS\''
Set @SQLStr=''copy ''+@BKFileName+'' ''+@DestFileName
Print @SQLStr
Execute Master..xp_cmdshell @SQLStr
Go
jcs 发表于 2006-8-31 11:46:46
yitang非常感谢你的帮助,按照你的方法,在服务器备份是成功了,但是没有拷贝到另一台机器上,麻烦你看看我写的代码有误吗
--Perform Full BackUp
Declare @FullFileName Varchar(200)
Declare @FileFlag varchar(20)
Set @FileFlag=convert(char(8),getdate(),112)
Set @FullFileName=''D:\JCS\JCS''+@FileFlag+''.BAK''
--完整备份,文件名 MIS_FULL20060831.BAK
BackUp DataBase YG_HJ_DB To Disk=@FullFileName with init
Go
--拷贝到远程电脑上
exec master..xp_cmdshell ''net use \\192.168.0.88\d$ password /user:012345\administrator''
Go
--Copy backup file to remote server
Declare @BKFileName varchar(200)
Declare @DestFileName varchar(200)
Declare @FileFlag varchar(8)
Declare @SQLStr varchar(300)
Set @FileFlag=convert(char(8),getdate(),112)
Set @BkFileName=''D:\JCS\JCS''+@FileFlag+''.BAK''
Set @DestFileName=''\\192.168.0.88\d$\JCS\''
Set @SQLStr=''copy ''+@BKFileName+'' ''+@DestFileName
Print @SQLStr
Execute Master..xp_cmdshell @SQLStr
Go
首先你在Dos窗口下运行一下
net use \\192.168.0.88\d$ password /user:012345\administrator
看看有没有报错,如果没报错的话,检查一下''\\192.168.0.88\d$\JCS\''这个路径存不存在?代码没有问题的,我就是这样备份的!
阅读(1827) | 评论(0) | 转发(0) |