SQL Server Management Studio 中的数据库 .bak 文件保存在哪里?

发布于 2024-10-12 11:08:38 字数 243 浏览 5 评论 0原文

我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

绝不放开 2024-10-19 11:08:38

应该在

Program Files>Microsoft SQL Server>MSSQL 1.0>MSSQL>BACKUP>

我的例子中,

C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Backup

如果您使用 gui 或 T-SQL,您可以指定您想要的位置
T-SQL 示例

BACKUP DATABASE [YourDB] TO  DISK = N'SomePath\YourDB.bak' 
WITH NOFORMAT, NOINIT,  NAME = N'YourDB Full Database Backup', 
SKIP, NOREWIND, NOUNLOAD,  STATS = 10
GO

使用 T-SQL,您还可以获取备份的位置,请参见此处 获取 SQL Server 数据库的物理设备名称和备份时间

SELECT          physical_device_name,
                backup_start_date,
                backup_finish_date,
                backup_size/1024.0 AS BackupSizeKB
FROM msdb.dbo.backupset b
JOIN msdb.dbo.backupmediafamily m ON b.media_set_id = m.media_set_id
WHERE database_name = 'YourDB'
ORDER BY backup_finish_date DESC

Should be in

Program Files>Microsoft SQL Server>MSSQL 1.0>MSSQL>BACKUP>

In my case it is

C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Backup

If you use the gui or T-SQL you can specify where you want it
T-SQL example

BACKUP DATABASE [YourDB] TO  DISK = N'SomePath\YourDB.bak' 
WITH NOFORMAT, NOINIT,  NAME = N'YourDB Full Database Backup', 
SKIP, NOREWIND, NOUNLOAD,  STATS = 10
GO

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

SELECT          physical_device_name,
                backup_start_date,
                backup_finish_date,
                backup_size/1024.0 AS BackupSizeKB
FROM msdb.dbo.backupset b
JOIN msdb.dbo.backupmediafamily m ON b.media_set_id = m.media_set_id
WHERE database_name = 'YourDB'
ORDER BY backup_finish_date DESC
笑饮青盏花 2024-10-19 11:08:38

如果备份不是在默认位置创建的,您可以使用此 T-SQL(在 SSMS 中运行)来查找 SQL Server 实例上所有数据库的最新备份的文件路径:

SELECT  DatabaseName = x.database_name,
        LastBackupFileName = x.physical_device_name,
        LastBackupDatetime = x.backup_start_date
FROM (  SELECT  bs.database_name,
                bs.backup_start_date,
                bmf.physical_device_name,
                  Ordinal = ROW_NUMBER() OVER( PARTITION BY bs.database_name ORDER BY bs.backup_start_date DESC )
          FROM  msdb.dbo.backupmediafamily bmf
                  JOIN msdb.dbo.backupmediaset bms ON bmf.media_set_id = bms.media_set_id
                  JOIN msdb.dbo.backupset bs ON bms.media_set_id = bs.media_set_id
          WHERE   bs.[type] = 'D'
                  AND bs.is_copy_only = 0 ) x
WHERE x.Ordinal = 1
ORDER BY DatabaseName;

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:

SELECT  DatabaseName = x.database_name,
        LastBackupFileName = x.physical_device_name,
        LastBackupDatetime = x.backup_start_date
FROM (  SELECT  bs.database_name,
                bs.backup_start_date,
                bmf.physical_device_name,
                  Ordinal = ROW_NUMBER() OVER( PARTITION BY bs.database_name ORDER BY bs.backup_start_date DESC )
          FROM  msdb.dbo.backupmediafamily bmf
                  JOIN msdb.dbo.backupmediaset bms ON bmf.media_set_id = bms.media_set_id
                  JOIN msdb.dbo.backupset bs ON bms.media_set_id = bs.media_set_id
          WHERE   bs.[type] = 'D'
                  AND bs.is_copy_only = 0 ) x
WHERE x.Ordinal = 1
ORDER BY DatabaseName;
┼── 2024-10-19 11:08:38

正如 Faiyaz 所说,要获取实例的默认备份位置,您无法将其放入 msdb,但必须查看注册表。您可以使用 xp_instance_regread 存储过程在 T-SQL 中获取它,如下所示:

EXEC  master.dbo.xp_instance_regread 
      N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQLServer',N'BackupDirectory'

双反斜杠 (\\) 是因为该键名称部分 (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:

EXEC  master.dbo.xp_instance_regread 
      N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQLServer',N'BackupDirectory'

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).

农村范ル 2024-10-19 11:08:38

为您的服务器实例设置注册表项。例如:

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

丿*梦醉红颜 2024-10-19 11:08:38

使用下面的脚本,并将 DatabaseName 与您已备份的数据库的名称进行切换。在物理设备名称列上,您将获得备份数据库的完整路径:

select a.backup_set_id, a.server_name, a.database_name, a.name, a.user_name, a.position, a.software_major_version, a.backup_start_date, backup_finish_date, a.backup_size, a.recovery_model, b.physical_device_name
from msdb.dbo.backupset a join msdb.dbo.backupmediafamily b
  on a.media_set_id = b.media_set_id
where a.database_name = 'DatabaseName'
order by a.backup_finish_date desc

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:

select a.backup_set_id, a.server_name, a.database_name, a.name, a.user_name, a.position, a.software_major_version, a.backup_start_date, backup_finish_date, a.backup_size, a.recovery_model, b.physical_device_name
from msdb.dbo.backupset a join msdb.dbo.backupmediafamily b
  on a.media_set_id = b.media_set_id
where a.database_name = 'DatabaseName'
order by a.backup_finish_date desc
带刺的爱情 2024-10-19 11:08:38

我不认为默认备份位置存储在 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

半世蒼涼 2024-10-19 11:08:38

因此最终在 SQL Server 2019 上,您可以调用内置的 SERVERPROPERTY 函数来查询默认备份文件夹:

select serverproperty('InstanceDefaultBackupPath')

So eventually on SQL Server 2019 you can just call built in SERVERPROPERTY function to query the default backup folder:

select serverproperty('InstanceDefaultBackupPath')
友谊不毕业 2024-10-19 11:08:38

...\Program Files\Microsoft SQL Server\MSSQL 1.0\MSSQL\Backup

...\Program Files\Microsoft SQL Server\MSSQL 1.0\MSSQL\Backup

提赋 2024-10-19 11:08:38

您是否尝试过:

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

老街孤人 2024-10-19 11:08:38

我也没有在那个标准位置找到它,但是查看数据库的属性,我发现确实进行了备份。

因此,我右键单击数据库并选择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.

不羁少年 2024-10-19 11:08:38

您可能想看一下这里,该工具将 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文