xcopy 在 SQL Server 上引发错误(xp_cmdshell 脚本)
在 SQL 上,我们通过 xp_cmdshell 脚本复制现有文件夹来创建一个新文件夹。
SQL脚本:
declare @cmd sysname
set @cmd = 'xcopy /t /e /i "C:\Rudresh\Process\001" "C:\Rudresh\Process\002" /O /X /H /K'
exec master..xp_cmdshell @cmd
脚本在执行时会抛出拒绝访问错误,并且我已经提供了所有文件夹权限。 请告诉我是否需要为 SQL 用户授予任何其他权限。?或者我是否错过了某些配置(NTFS 或 ACL 权限)
注意:如果我从脚本中删除 /O /X 并创建目录,则脚本可以正常工作。
on SQL we are creating a new folder by copying and existing folder by xp_cmdshell script.
SQL Script:
declare @cmd sysname
set @cmd = 'xcopy /t /e /i "C:\Rudresh\Process\001" "C:\Rudresh\Process\002" /O /X /H /K'
exec master..xp_cmdshell @cmd
Script will throw Access Denied error upon execution and I have provided all the folder permission.
kindly let me know is there any other permission i need to grant for SQL User.? or do i missed something configure (NTFS or ACL permissions)
Note: Script works fine if i remove /O /X from the script and creates the directory.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当 SQL Server 打开并使用 SQL Server 数据库文件时,您无法安全地创建 SQL Server 数据库文件的纯副本。因此,这些文件通常由 SQL Server 打开,不允许任何共享,甚至共享读取。有一种访问权限甚至可以绕过这一点,但我不推荐它,因为复制的文件可能会损坏且无法使用。
许多(大多数?)备份工具和产品可以安全地复制这些文件,但这是因为它们使用特殊的 SQL Server 接口和/或互锁来确保它们不会获得因 SQL Server 中途更改内容而损坏的文件。复制。
因此,此问题的解决方案是:
You cannot safely do a plain copy of SQL Server database files when that database is open and in use by SQL Server. For this reason, these files are typically opened by SQL Server disallowing any sharing, even shared reads. There is an access privilege that can bypass even this, but I do not recommend it as the copied files will likely be corrupt and unusable.
Many (most?) BACKUP tools and products can safely copy these files, but this is because they use a special SQL Server interface and/or interlock to insure that they do not get files that are corrupted by SQL Server changing the contents midway through a copy.
So the solutions to this problem are either: