sql server 备份恢复
备份
BACKUP DATABASE [lys]
TO DISK = N'D:\liyuanshuai\test\sqlserver_bakfile\lys20241219.bak'
WITH NOFORMAT, NOINIT, NAME = N'lys-完整 数据库 备份',
SKIP, NOREWIND, NOUNLOAD,
COMPRESSION,
STATS = 10
GO
完整备份还原
---还原之后可以直接使用
RESTORE DATABASE [lys_12] FROM DISK = N'D:\liyuanshuai\test\sqlserver_bakfile\lys20241219.bak'
WITH FILE = 1,
MOVE N'lys' TO N'D:\liyuanshuai\test\sqlserver_bakfile\lys\lys_12.mdf',
MOVE N'lys_02' TO N'D:\liyuanshuai\test\sqlserver_bakfile\lys\lys_12_02.ndf',
MOVE N'lys_sec' TO N'D:\liyuanshuai\test\sqlserver_bakfile\lys\lys_12_sec.ndf',
MOVE N'lys_if' TO N'D:\liyuanshuai\test\sqlserver_bakfile\lys\lys_12_if.ndf',
MOVE N'lys_log' TO N'D:\liyuanshuai\test\sqlserver_bakfile\lys\lys_12_log.ldf',
MOVE N'lys_log2' TO N'D:\liyuanshuai\test\sqlserver_bakfile\lys\lys_12_log2.ldf',
NOUNLOAD, STATS = 5
GO
分阶段还原,先还原全备,使数据库处于noreovery状态,然后再还原日志备份
---还原后可以继续还原log file
USE [master]
RESTORE DATABASE [lys_12]
FROM DISK = N'D:\liyuanshuai\test\sqlserver_bakfile\lys20241219.bak'
WITH FILE = 1,
MOVE N'lys' TO N'D:\liyuanshuai\test\sqlserver_bakfile\lys\lys.mdf',
MOVE N'lys_02' TO N'D:\liyuanshuai\test\sqlserver_bakfile\lys\lys_02.ndf',
MOVE N'lys_sec' TO N'D:\liyuanshuai\test\sqlserver_bakfile\lys\lys_sec.ndf',
MOVE N'lys_if' TO N'D:\liyuanshuai\test\sqlserver_bakfile\lys\lys_if.ndf',
MOVE N'lys_log' TO N'D:\liyuanshuai\test\sqlserver_bakfile\lys\lys_log.ldf',
MOVE N'lys_log2' TO N'D:\liyuanshuai\test\sqlserver_bakfile\lys\lys_log2.ldf',
NORECOVERY, NOUNLOAD, STATS = 5
GO
--还原日志备份
RESTORE LOG [lys_12]
FROM DISK = N'D:\liyuanshuai\test\sqlserver_bakfile\lys20241219_1307.trn'
WITH NOUNLOAD, STATS = 10
GO