简体   繁体   English

SQL Server备份到UNC

[英]Sql Server Backup to UNC

I've create a maintenance plan on my SQL Server 2005 server. 我已经在SQL Server 2005服务器上创建了维护计划。 The backup should be written to another server. 备份应写入另一台服务器。 I'm using a UNC path for this. 我为此使用UNC路径。 The user running the SQL Agent jobs has full access to the other server. 运行SQL Agent作业的用户对另一台服务器具有完全访问权限。 It's admin on both servers. 在两台服务器上都是管理员。

The problem is that this statement fails ( has the correct server name ofcourse): 问题是该语句失败(具有正确的课程服务器名称):

EXECUTE master.dbo.xp_create_subdir N'\\\\servername\\c$\\SqlServerBackup\\Test' 执行master.dbo.xp_create_subdir N'\\\\ servername \\ c $ \\ SqlServerBackup \\ Test'

The error I get is: Msg 22048, Level 16, State 1, Line 0 xp_create_subdir() returned error 123, 'The filename, directory name, or volume label syntax is incorrect.' 我得到的错误是:消息22048,级别16,状态1,行0 xp_create_subdir()返回了错误123,“文件名,目录名或卷标签语法不正确。”

Does anyone know what could be the problem? 有谁知道可能是什么问题?

After having this problem myself, with none of the above solutions being clear enough, I thought I'd post a clearer response. 我自己遇到了这个问题,但上述解决方案都不够清晰,我想我会发布一个更清晰的答案。 The error is in fact nothing to do with syntax - it is entirely to do with permissions. 该错误实际上与语法无关-完全与权限有关。 The important thing here is that it is the SQL Server service account, NOT the SQL Server Agent account, that attempts to log in to create the directory. 这里重要的是尝试登录以创建目录的是SQL Server服务帐户而不是SQL Server代理帐户。 You can check your Event Viewer on the target server and look at the security log to see the failed logins from the SQL Server account on the other machine (mine was running as a local administrator). 您可以在目标服务器上检查事件查看器,并查看安全日志,以查看来自另一台计算机上的SQL Server帐户的失败登录(我以本地管理员身份运行)。

To solve this, set your SQL Server service account to be a domain user that's allowed to write to the remote share. 若要解决此问题,请将您的SQL Server服务帐户设置为允许写入远程共享的域用户。 I would have expected SQL Server Agent to be able to use its own credentials to perform these backup operations, but apparently not! 我希望SQL Server代理能够使用其自己的凭据来执行这些备份操作,但是显然不能!

SQL Agent does not actually run backups, it is capable of executing commands in SQL Server which performs the backup. SQL Agent实际上并不运行备份,它能够在执行备份的SQL Server中执行命令。 Threfore, the SQL Server service account is the one that needs permissions to the UNC share. 因此,SQL Server服务帐户是需要UNC共享权限的帐户。

However, I think there is an actual issue with the xp_create_subdir procedure. 但是,我认为xp_create_subdir过程存在实际问题。 I am going to stop using maintenance plans because I get this exact same error every once in a while. 我将停止使用维护计划,因为有时我会得到完全相同的错误。 No permissions are changing and it "usually" works, but "usually" doesn't cut it. 没有权限在更改,它“通常”有效,但是“通常”不会减少权限。

If you are running the SQL Server And/Or SQL Server Agent Service as 'LocalSystem' but are resistant to change the SQL Server and SQL Server Agent accounts to Domain Accounts, try this: 如果您以“ LocalSystem”身份运行SQL Server和/或SQL Server代理服务,但无法将SQL Server和SQL Server代理帐户更改为“域帐户”,请尝试以下操作:

  1. If you are using a SQL Server Agent Proxy account/credentials to execute part of a task and backup using SQL Agent, on the UNC backup destination under the share and NTFS permissions, grant Full/Modify permissions (respectively) as they do get used at one point during the process of establishing connections or at least in the SQL backup jobs I've tried (at least according to the Security Logs). 如果您使用SQL Server代理代理帐户/凭据执行部分任务并使用SQL代理进行备份,请在UNC备份目标上的共享和NTFS权限下,分别授予“完全/修改”权限,因为它们确实在在建立连接过程中或至少在我尝试过的SQL备份作业中(至少根据安全日志)有一点。 Unfortunately, there either isn't a way or I haven't found a way to perform certain SQL Server Service tasks by using Proxy Accounts that you can do with a purely SQL Agent task (as noted in earlier posts by User55852 and ZaDDaZ). 不幸的是,或者没有办法,或者我还没有找到一种方法来使用纯SQL代理任务可以执行的代理帐户来执行某些SQL Server服务任务(如User55852和ZaDDaZ在之前的文章中所述)。

  2. On the UNC backup destination server under the share and NTFS permissions, grant Full/Modify permissions (respectively) to the Computer account of the SQL server (source server). 在共享和NTFS权限下的UNC备份目标服务器上,分别向SQL服务器(源服务器)的计算机帐户授予“完全/修改”权限。


This does work for those cases where the SQL Services run as 'LocalSystem', but need to reach into another server to drop a backup. 这对于SQL Services以“ LocalSystem”运行但需要进入另一台服务器以删除备份的情况确实适用。

And of course, best practices state that for each SQL Service, they should have their own domain account with least privilage, which instead of adding the Computer account of the server which exposes much more access to the share than should be allowed - essentially anything executing as the Computer account or 'LocalSystem'. 当然,最佳实践表明,对于每个SQL Service,它们应该拥有自己的域帐户,且特权最少,这不是添加服务器的计算机帐户,该计算机帐户公开了对共享的访问权限超过了应有的权限-本质上是任何执行作为计算机帐户或“ LocalSystem”。

I saw this error in Maintenance plan history. 我在维护计划历史记录中看到此错误。

Operating system error 3(The system cannot find the path specified.). 操作系统错误3(系统找不到指定的路径。)。 BACKUP DATABASE is terminating abnormally.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly. BACKUP DATABASE异常终止。”。可能的失败原因:查询问题,“ ResultSet”属性未正确设置,参数未正确设置或连接未正确建立。

I tried to run first piece of Backup step where it was creating directory on share. 我尝试运行备份步骤的第一步,在该步骤中共享创建目录。 I got access denied error. 我收到访问被拒绝的错误。

Finally, I gave full permissions to service account under which SQL Agent runs and maintenance plan was successfully running. 最后,我授予了运行SQL Agent并成功运行维护计划的服务帐户的全部权限。

Check the he account SqlAgent is runs on. 检查运行SqlAgent的帐户。 Usually it system\\NetworkService ant it does not have access rights on other computers. 通常它是system \\ NetworkService ant,它在其他计算机上没有访问权限。

Either give temporarily write rights to everyone on the UNC path or in Control Panel/Services change the account used for SqlAgent. 暂时向UNC路径上的每个人授予写权限,或者在“控制面板/服务”中更改用于SqlAgent的帐户。

在服务器名称之前是否不缺少双反斜杠?

I've backed-up up to UNC's mmany times. 我已经备份了UNC的大部分时间。 Make sure it's not a permissions issue w/ the account that sql server and sql agent are running as. 确保不是与运行sql server和sql agent的帐户有关的权限问题。 I wouldn't back up to the hidden admin share like that perhaps it's the $ that's causing the problem. 我不会备份到隐藏的管理员共享,也许是导致问题的原因是$。 Create a share and backup to that. 创建一个共享并备份。 \\server\\share NOT \\server\\c$\\folder \\ server \\ share NOT \\ server \\ c $ \\ folder

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM