简体   繁体   English

从.bak文件恢复文件列表时出错

[英]Error restoring a filelistonly from .bak file

I am trying to restore the filelistonly from a .bak file and am getting the following error: 我试图从.bak文件中恢复fileliston并收到以下错误:

Msg 3201, Level 16, State 2, Line 1 Cannot open backup device 'C:\\Users...\\myFile.bak'. 消息3201,级别16,状态2,行1无法打开备份设备'C:\\ Users ... \\ myFile.bak'。 Operating system error 5(Access is denied.). 操作系统错误5(访问被拒绝。)。

The file was initially blocked, but I unblocked it, so that shouldn't be the problem. 该文件最初被阻止,但我取消阻止它,所以这不应该是问题。

The error message explains exactly what is happening: you've placed the .BAK file in a folder that the SQL Server service account does not have access to. 错误消息准确说明了发生的情况:您已将.BAK文件放在SQL Server服务帐户无权访问的文件夹中。

You could "fix" this by granting access to your profile folder to the SQL Server service account, but this is an unnecessary violation of security best practices. 您可以通过授予对SQL Server服务帐户的配置文件文件夹的访问权限来“修复”此问题,但这是对安全最佳实践的不必要的违反。

Much easier to just move the file to a location where the SQL Server service account already has native access, like the backup or data directory. 将文件移动到SQL Server服务帐户已具有本机访问权限的位置(如备份或数据目录)要容易得多。 You can find the data folder (there may be multiple valid locations) by looking at the result of the following query: 您可以通过查看以下查询的结果找到数据文件夹(可能有多个有效位置):

SELECT DISTINCT SUBSTRING(physical_name, 1, LEN(physical_name) 
  - CHARINDEX('\', REVERSE(physical_name)) + 1) 
FROM [master].sys.master_files
WHERE [type] = 0;

And if you've backed up any databases (let's hope you have!), you can find out some valid backup locations this way: 如果您已备份任何数据库(希望您拥有!),您可以通过以下方式找到一些有效的备份位置:

SELECT DISTINCT SUBSTRING(physical_device_name, 1, LEN(physical_device_name) 
  - CHARINDEX('\', REVERSE(physical_device_name)) + 1) 
FROM msdb.dbo.backupmediafamily;

Of course these don't take things into account such as read-only data files on read-only volumes, volumes SQL Server might have access to but you don't, volumes without enough free space for your .BAK file, or backup locations that have been used in the past but are no longer present or accessible. 当然,这些都没有考虑到因素,例如只读卷上的只读数据文件,SQL Server可能有权访问但没有访问的卷,没有足够空间用于.BAK文件的卷或备份位置过去曾使用但不再存在或无法访问的。

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

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