我有下面的脚本来生成服务器所有基础的备份,手动执行它可以工作,但是当我运行JOB时,它会执行但不执行它必须做的.. 我需要备份到同一网络上的存储。 一切都可以手动完成,但不能正常工作
--================================================================================================================================================================
--CRIA MAPEAMENTO E LIMPA BACKUP ANTERIOR
--================================================================================================================================================================
exec xp_cmdshell 'net use y: /delete'
go
exec xp_cmdshell 'if not exist y:\ net use y: CAMINHO /user:usuario senha'
go
--================================================================================================================================================================
--cria tabela do dia
--================================================================================================================================================================
declare @p_dia varchar(100),@cmd varchar(100)
set @p_dia = replace(convert(varchar(7),getdate(),121),'-','\') + '\' + convert(varchar(10),getdate(),112) + '\' +
reverse(substring(reverse(cast(CONNECTIONPROPERTY('local_net_address') as varchar(100))),1,charindex('.',
reverse(cast(CONNECTIONPROPERTY('local_net_address') as varchar(100))))-1))
select @p_dia
set @cmd = 'exec xp_create_subdir ''Y:\' + @p_dia + ''''
exec(@cmd)
set @cmd = 'exec xp_cmdshell ''del /s/q Y:\' + @p_dia + '\*.*'''
exec(@cmd)
--================================================================================================================================================================
--BASES NAO HISTORICO - BACKUP FULL DIARIO
--================================================================================================================================================================
IF OBJECT_ID('MASTER.DBO.TBL_BASES_BACKUP') IS NOT NULL
DROP TABLE TBL_BASES_BACKUP
select
name,
row_number() over(order by (select null)) as contador
INTO TBL_BASES_BACKUP
from sys.databases
where name not like '%hist%'
and name not in('tempdb')
DECLARE @I INT = 0 ,
@CMD2 VARCHAR(MAX) ='',
@base varchar(100) = '',
@data_Formatada varchar(10) = replace(convert(varchar(10),getdate(),103),'/','_')
while @i <= (select max(contador) from TBL_BASES_BACKUP)
begin
set @base = (select name from TBL_BASES_BACKUP where contador = @i)
set @CMD2 = '
BACKUP DATABASE ' + quotename(@base) + ' TO DISK = ''Y:\'+@p_dia+'\'+@base+'_backup_'+@data_Formatada+'_230032_0713493.bak''
WITH NOFORMAT, NOINIT, NAME = N'''+@base+'-Completo Banco de Dados Backup'', SKIP, NOREWIND, NOUNLOAD, COMPRESSION, STATS = 10
'
exec(@cmd2)
set @i = @i + 1
end