我在数据库服务器上有一堆.bak
个文件,我创建了一个存储过程来执行它(目前在master中)。执行我的存储过程似乎正确地覆盖我的数据几乎,但它遗漏了.bak
文件中包含的最新数据。
如果我手动恢复.bak
,我拥有所有数据,当我的存储过程执行此操作时,我遗漏了一些数据。我有预感它的WITH REPLACE?没有它我会得到一些其他错误。
-- Insert statements for procedure here
ALTER DATABASE dbName SET SINGLE_USER WITH ROLLBACK IMMEDIATE
RESTORE Database dbName
FROM DISK = N'C:\Backups\Databases\dbName.bak'
WITH REPLACE,
MOVE 'dbName' TO N'C:\Backups\Databases\DATA\dbName.mdf',
MOVE 'dbName_log' TO N'C:\Backups\Databases\DATA\dbName.ldf',
NOUNLOAD, STATS = 5
ALTER DATABASE dbName
SET MULTI_USER WITH ROLLBACK IMMEDIATE
我对SQL Server不太满意,有人对如何解决我的问题有任何指导吗?
解决方案:设置FILE = n
我没有指定它,默认情况下假设为1我相信,将其设置为4(最新备份)解决了我的问题
答案 0 :(得分:1)
在您的查询中,您没有将任何文件组移动到特定文件夹loaction中尝试像这样
USE [master]
ALTER DATABASE [AdventureWorks2012] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
RESTORE DATABASE [AdventureWorks2012_Temp]
FROM DISK = N'D:\Backup\AdventureWorks2012.bak'
WITH FILE = 1,
MOVE N'AdventureWorks2012_Data' TO N'D:\Backup\AdventureWorks\AdventureWorks2012_1.mdf',
MOVE N'AdventureWorks2012_Log' TO N'D:\Backup\AdventureWorks\AdventureWorks2012_1_Log.ldf',
NOUNLOAD, STATS = 5
GO
ALTER DATABASE [AdventureWorks2012] SET MULTI_USER WITH ROLLBACK IMMEDIATE
答案 1 :(得分:-1)
试试这种方式
RESTORE DATABASE ReportServerSplitCopy FROM
DISK = 'D:\DBBackups\ReportServer\ReportServer_Split1.bak'
,DISK = 'D:\DBBackups\ReportServer\ReportServer_Split2.bak'
,DISK = 'D:\DBBackups\ReportServer\ReportServer_Split3.bak'
WITH REPLACE ,
MOVE 'ReportServer' TO 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER11\MSSQL\DATA\ReportServerSplitCopy.mdf',
MOVE 'ReportServer_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER11\MSSQL\DATA\ReportServerSplitCopy_log.ldf'
GO