USE [master]
GO
--备份,将备份成2个文件,两个文件的大小基本一致
BACKUP DATABASE [AdventureWorks2014] TO
DISK=N'd:\database_bak\AdventureWorks2014_1.bak',
DISK=N'd:\database_bak\AdventureWorks2014_2.bak'
with Format,COMPRESSION,STATS=10
--查看备份文件中的数据库信息,2个文件都是一样的
RESTORE FileListOnly From Disk=N'd:\database_bak\AdventureWorks2014_1.bak'
RESTORE FileListOnly From Disk=N'd:\database_bak\AdventureWorks2014_2.bak'
--恢复前准备:先删除相关进程
DECLARE @sql NVARCHAR(MAX)
SELECT @sql=isnull(@sql,'')+'kill '+CAST(spid AS VARCHAR(50))+';'
FROM sys.sysprocesses AS s
WHERE s.spid>50 AND s.spid<>@@SPID AND DB_NAME(s.dbid)='AdventureWorks2014'
EXEC( @sql )
--恢复
RESTORE DATABASE [AdventureWorks2014]
FROM
DISK = N'd:\database_bak\AdventureWorks2014_1.bak',
DISK = N'd:\database_bak\AdventureWorks2014_2.bak'
WITH FILE = 1,
MOVE N'AdventureWorks2014_Data' TO N'D:\database\2014\AdventureWorks2014_Data.mdf',
MOVE N'AdventureWorks2014_Log' TO N'D:\database\2014\AdventureWorks2014_Log.ldf',
NOUNLOAD, REPLACE, STATS = 5