SQL Server Management Studio 中的数据库 .bak 文件保存在哪里?
我尝试使用 SQL Server Management Studio 2008 Express 为我的 SQL Server 数据库创建备份。我已经创建了备份,但它保存在我无法找到的某个路径中。我将其保存在本地硬盘上,并签入了 Program Files>Microsoft SQL Server>MSSQL 1.0>MSSQL>DATA>
但它不在那里。
该 DB .bak 的默认保存路径是什么?
I was trying to create a backup for my SQL Server Database using SQL Server Management Studio 2008 Express. I have created the backup but it is getting saved at some path which I am not able to find. I am saving it on my local HD and I checked in Program Files>Microsoft SQL Server>MSSQL 1.0>MSSQL>DATA>
but its not there.
What's the default save path for this DB .bak?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
应该在
我的例子中,
如果您使用 gui 或 T-SQL,您可以指定您想要的位置
T-SQL 示例
使用 T-SQL,您还可以获取备份的位置,请参见此处 获取 SQL Server 数据库的物理设备名称和备份时间
Should be in
In my case it is
If you use the gui or T-SQL you can specify where you want it
T-SQL example
With T-SQL you can also get the location of the backup, see here Getting the physical device name and backup time for a SQL Server database
如果备份不是在默认位置创建的,您可以使用此 T-SQL(在 SSMS 中运行)来查找 SQL Server 实例上所有数据库的最新备份的文件路径:
If the backup wasn't created in the default location, you can use this T-SQL (run this in SSMS) to find the file path for the most recent backup for all DBs on your SQL Server instance:
正如 Faiyaz 所说,要获取实例的默认备份位置,您无法将其放入 msdb,但必须查看注册表。您可以使用 xp_instance_regread 存储过程在 T-SQL 中获取它,如下所示:
双反斜杠 (\\) 是因为该键名称部分 (Microsoft SQL Server) 中存在空格。
“MSSQL12.MSSQLSERVER”部分是 SQL 2014 的默认实例名称。您必须适应以放置您自己的实例名称(查看注册表)。
As said by Faiyaz, to get default backup location for the instance, you cannot get it into msdb, but you have to look into Registry. You can get it in T-SQL in using xp_instance_regread stored procedure like this:
The double backslash (\\) is because the spaces into that key name part (Microsoft SQL Server).
The "MSSQL12.MSSQLSERVER" part is for default instance name for SQL 2014. You have to adapt to put your own instance name (look into Registry).
为您的服务器实例设置注册表项。例如:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.2\MSSQLServer\BackupDirectory
Set registry item for your server instance. For example:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.2\MSSQLServer\BackupDirectory
使用下面的脚本,并将
DatabaseName
与您已备份的数据库的名称进行切换。在物理设备名称列上,您将获得备份数据库的完整路径:Use the script below, and switch the
DatabaseName
with then name of the database that you've backed up. On the column physical_device_name, you'll have the full path of your backed-up database:我不认为默认备份位置存储在 SQL Server 本身内。
设置存储在注册表中。查找“BackupDirectory”键,您将找到默认备份。
“msdb.dbo.backupset” 表包含已进行的备份列表,如果未对数据库进行备份,则不会显示任何内容
I dont think default backup location is stored within the SQL server itself.
The settings are stored in Registry. Look for "BackupDirectory" key and you'll find the default backup.
The "msdb.dbo.backupset" table consists of list of backups taken, if no backup is taken for a database, it won't show you anything
因此最终在 SQL Server 2019 上,您可以调用内置的 SERVERPROPERTY 函数来查询默认备份文件夹:
So eventually on SQL Server 2019 you can just call built in SERVERPROPERTY function to query the default backup folder:
...\Program Files\Microsoft SQL Server\MSSQL 1.0\MSSQL\Backup
...\Program Files\Microsoft SQL Server\MSSQL 1.0\MSSQL\Backup
您是否尝试过:
C:\Program Files\Microsoft SQL Server\MSSQL10.SQL2008\MSSQL\Backup
获取上周所有备份的脚本可以在以下位置找到:
http://wraithnath.blogspot.com/2010/12/how-to-find-all-database- backups-in.html
我还有更多备份 SQL 脚本,位于
http:// wraithnath.blogspot.com/search/label/SQL
have you tried:
C:\Program Files\Microsoft SQL Server\MSSQL10.SQL2008\MSSQL\Backup
Script to get all backups in the last week can be found at:
http://wraithnath.blogspot.com/2010/12/how-to-find-all-database-backups-in.html
I have plenty more backup SQL scripts there also at
http://wraithnath.blogspot.com/search/label/SQL
我也没有在那个标准位置找到它,但是查看数据库的属性,我发现确实进行了备份。
因此,我右键单击数据库并选择
Tasks-Backup...
并查看目的地。那是我找到我的文件的地方。这是使用 SQL 2012。
I didn't find it in that standard location, either, but looking at the Properties of the database I saw a backup was indeed taken.
So I right-clicked the database and selected
Tasks-Backup...
and looked at the destinations. That is where I found my files.This is using SQL 2012.
您可能想看一下这里,该工具将 BAK 文件从远程 SQL Server 保存到本地硬盘: FIDA BAK 到本地
You may want to take a look here, this tool saves a BAK file from a remote SQL Server to your local harddrive: FIDA BAK to local