简体   繁体   English

SQL Server-使用RESTORE复制数据库,结果复制没有数据

[英]SQL Server - Using RESTORE to copy database, resulting copy has no data

Whenever I try to create a copy of my database using the BACKUP and RESTORE commands, the copy is created, but contains no data. 每当我尝试使用BACKUP和RESTORE命令创建数据库副本时,都会创建该副本,但不包含任何数据。 I'm running the following commands, and get success status back: 我正在运行以下命令,并获得成功状态:

BACKUP DATABASE [SomeDB]
    TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\SomeDB.bak'
BACKUP DATABASE successfully processed 161 pages in 0.021 seconds (62.805 MB/sec).

RESTORE DATABASE [SomeDB_Copy]
    FROM DISK=N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\SomeDB.bak'
    WITH MOVE N'SomeDB' TO N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\SomeDB_copy.mdf',
    MOVE N'SomeDB_log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\SomeDB_copy.ldf'
RESTORE DATABASE successfully processed 162 pages in 0.095 seconds (13.958 MB/sec).

Am I missing a step? 我错过了一步吗? All of the examples I found use this method. 我发现的所有示例都使用此方法。 Even on StackOverflow . 即使在StackOverflow上 This is on SQL Server 2005. 这是在SQL Server 2005上。

Update:. 更新:。 I backed up the database to a new file, and restored using that and everything worked fine. 我将数据库备份到一个新文件,并使用该文件进行还原,一切正常。 I don't know if my original file was corrupted, or something else weird was going on. 我不知道我的原始文件是否已损坏,或者发生了其他奇怪的事情。

I realize this topic is old but I wanted to expand on what usr said in his comment about the multi-file backupset, although I would have called it a multi-backup device. 我意识到这个话题很老,但是我想扩展一下usr在他关于多文件备份集的评论中所说的内容,尽管我将其称为多备份设备。 The fact that your backup command processed 161 pages yet the restore processed 162 pages makes me think you have more than one backup in your device/file. 您的备份命令处理了161页而还原处理了162页,这一事实使我认为您的设备/文件中有多个备份。 You can use the INIT clause on the backup command to guarantee that you only have a single backup in the device: 您可以在backup命令上使用INIT子句以确保设备中只有一个备份:

BACKUP DATABASE [SomeDB]
TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\SomeDB.bak' 
with init;

From the Microsoft documentation at http://msdn.microsoft.com/en-us/library/ms186865.aspx : 从位于http://msdn.microsoft.com/zh-cn/library/ms186865.aspx的Microsoft文档中:

A disk device does not have to exist before it is specified in a BACKUP statement. 在BACKUP语句中指定磁盘设备之前,它不必存在。 If the physical device exists and the INIT option is not specified in the BACKUP statement, the backup is appended to the device. 如果物理设备存在并且在BACKUP语句中未指定INIT选项,则备份将附加到该设备。

You should be able to use the HEADERONLY option on the RESTORE command to check whether there are multiple backups in a device/file. 您应该能够使用RESTORE命令上的HEADERONLY选项来检查设备/文件中是否有多个备份。

BACKUP DATABASE [SomeDB]
TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\SomeDB.bak' 
with init;

RESTORE HEADERONLY 
FROM DISK = = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\SomeDB.bak'; 

BACKUP DATABASE [SomeDB]
TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\SomeDB.bak';

RESTORE HEADERONLY 
FROM DISK = = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\SomeDB.bak';

The output from the first RESTORE HEADERONLY will show one backup in the file while the output from the second should show there are two backups in the file. 第一个RESTORE HEADERONLY的输出将在文件中显示一个备份,而第二个RESTORE HEADERONLY的输出应在文件中显示两个备份。

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

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