还是拿数据库AAAAAAAA为例子
CREATE PROC [dbo].[p_log_backupAAAAAAAA]
@dbname sysname='',
@bkflogname NVARCHAR(260)='',
@bkpath NVARCHAR(260)='w:'
AS
DECLARE @sql VARCHAR(8000)
EXEC master..xp_cmdshell 'net use w: \\具体IP\子目录 密码 /user:dataserver\账户'
IF ISNULL(@dbname,'')='' SET @dbname=DB_NAME()
IF RIGHT(@bkpath,1)<>'\' SET @bkpath=@bkpath+'\'
IF ISNULL(@bkflogname,'')='' SET @bkflogname='\DBNAME\_\DATE\_\TIME\.bak'
SET @bkpath=@bkpath+CONVERT(VARCHAR,GETDATE(),112)+'\'+'EVENT_LOG'
SET @sql='md '+@bkpath+'\'+@dbname
EXEC master..xp_cmdshell @sql,no_output
SET @bkflogname=REPLACE(REPLACE(REPLACE(@bkflogname,'\DBNAME\',@dbname)
,'\DATE\',CONVERT(VARCHAR,GETDATE(),112))
,'\TIME\',REPLACE(CONVERT(VARCHAR,GETDATE(),108),':',''))
SET @sql='backup LOG '+@dbname
+' to disk='''+@bkpath+'\'+@dbname+'\'+@bkflogname+''''+' WITH RETAINDAYS = 3, NOFORMAT, NOINIT, SKIP, REWIND, NOUNLOAD, STATS = 10'
EXEC(@sql)
EXEC master..xp_cmdshell 'net use w: /del'