YourSQLDba的共享路径备份遭遇重启问题
2019-09-25 14:32 潇湘隐者 阅读(645) 评论(0) 收藏 举报如果YourSQLDba设置过共享路径备份(具体参考博客YourSQLDba设置共享路径备份),有时候服务器重启后,备份就会出错,具体错误信息类似如下所示:
Date 2019/9/25 10:10:00
Log SQL Server (Current - 2019/9/25 3:06:00)
Source spid56
Message
BackupDiskFile::CreateMedia: Backup device 'M:\xxx\LOG_BACKUP\msdb_[2019-09-24_00h08m06_Tue]_logs.TRN' failed to create. Operating system error 3(系统找不到指定的路径。).
出现这个问题,需要使用Exec YourSQLDba.Maint.CreateNetworkDriv设置网络路径,即使之前设置过网络路径,查询[YourSQLDba].[Maint].[NetworkDrivesToSetOnStartup]表也有相关网络路径设置,但是确实需要重新设置才能消除这个错误。
EXEC sp_configure 'show advanced option', 1;
GORECONFIGURE;GOsp_configure 'xp_cmdshell', 1;GORECONFIGURE;GOEXEC YourSQLDba.Maint.CreateNetworkDrives @DriveLetter = 'M:\',
@unc = 'xxxxxxxxxx;GO
sp_configure 'xp_cmdshell', 0;GO
EXEC sp_configure 'show advanced option', 1;GORECONFIGURE;
查看了一下 [Maint].[CreateNetworkDrives]存储过程,应该是重启过后,需要运行net use这样的命令进行相关配置。
USE [YourSQLDba]GOSET ANSI_NULLS ON
GOSET QUOTED_IDENTIFIER ON
GOALTER proc [Maint].[CreateNetworkDrives]
@DriveLetter nvarchar(2)
, @unc nvarchar(255)
asBeginDeclare @errorN int
Declare @cmd nvarchar(4000)Set nocount on
Exec yMaint.SaveXpCmdShellStateAndAllowItTemporary Set @DriveLetter=rtrim(@driveLetter) Set @Unc=rtrim(@Unc) If Len(@DriveLetter) = 1Set @DriveLetter = @DriveLetter + ':'
If Len(@Unc) >= 1 Begin Set @Unc = yUtl.NormalizePath(@Unc)Set @Unc = Stuff(@Unc, len(@Unc), 1, '')
EndSet @cmd = 'net use <DriveLetter> /Delete'
Set @cmd = Replace( @cmd, '<DriveLetter>', @DriveLetter)
begin try Print @cmd exec xp_cmdshell @cmd, no_output end try begin catch end catch-- suppress previous network drive definition
If exists(select * from Maint.NetworkDrivesToSetOnStartup Where DriveLetter = @driveLetter)
BeginDelete from Maint.NetworkDrivesToSetOnStartup Where DriveLetter = @driveLetter
End Begin TrySet @cmd = 'net use <DriveLetter> <unc>'
Set @cmd = Replace( @cmd, '<DriveLetter>', @DriveLetter )
Set @cmd = Replace( @cmd, '<unc>', @unc )
Print @cmd exec xp_cmdshell @cmdInsert Into Maint.NetworkDrivesToSetOnStartup (DriveLetter, Unc) Values (@DriveLetter, @unc)
Exec yMaint.RestoreXpCmdShellState End Try Begin CatchSet @errorN = ERROR_NUMBER() -- return error code
Print convert(nvarchar, @errorN) + ': ' + ERROR_MESSAGE()
Exec yMaint.RestoreXpCmdShellState End CatchEnd -- Maint.CreateNetworkDrives
扫描上面二维码关注我
如果你真心觉得文章写得不错,而且对你有所帮助,那就不妨帮忙“推荐"一下,您的“推荐”和”打赏“将是我最大的写作动力!
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接.
浙公网安备 33010602011771号