--数据库备份压缩拷贝实例:前提要安装RAR压缩软件
  --声明变量
  declare @day varchar(10),@dbname varchar(20),@filename varchar(100),@cmd_str varchar(500),@local_name varchar(500)
  --初始变量值
  set @day = convert(varchar(10),getdate(),112)
  set @dbname='database'
  set @filename=@dbname+@day
  set @local_name='y:ackupdatabase'+@filename
  --sql备份
  backup database database to disk=@local_name with init
  --删除备份
  set @cmd_str='del y:ackupdatabase'+@dbname + convert(varchar(10),DATEADD(DAY,-2,getdate()),112)
  EXEC master..xp_cmdshell @cmd_str
  --删除RAR
  set @cmd_str='del y:ackupdatabase'+@dbname+'.rar'
  EXEC master..xp_cmdshell @cmd_str
  --压缩到网络驱动器上
  set @cmd_str='"C:Program FilesWinRARWinRAR.exe" a y:ackupdatabase'+@dbname+'.rar ' + @local_name
  print @cmd_str+char(10)
  EXEC master..xp_cmdshell @cmd_str
  --网络认证
  EXEC master..xp_cmdshell 'net use w: \200.168.15.9ackup "baijin830" /user:"WINDOWS-72AMTFXadministrator"',no_output
  --网络拷贝
  set @cmd_str='copy x:ackupdatabase'+ @dbname+'.rar ' + 'w:'
  print @cmd_str+char(10)
  EXEC master..xp_cmdshell @cmd_str
  go