我使用以下脚本制作生产数据库的 .bak 文件并将其保存到测试服务器,如果需要,可以在该服务器上恢复。该脚本未说明要压缩文件。运行 SQL Server 2019 Enterprise。
BACKUP DATABASE [PINK]
TO DISK = N'\\TestServer\Transfer\PINK.bak'
WITH NOFORMAT, INIT, NAME = N'PINK', SKIP, NOREWIND, NOUNLOAD, STATS = 10, CHECKSUM
GO
DECLARE @backupSetId AS int
SELECT @backupSetId = position
FROM msdb..backupset
WHERE database_name = N'PINK'
AND backup_set_id = (SELECT MAX(backup_set_id)
FROM msdb..backupset
WHERE database_name = N'PINK')
IF @backupSetId IS NULL
BEGIN
RAISERROR(N'Verify failed. Backup information for database ''PINK'' not found.', 16, 1)
END
RESTORE VERIFYONLY
FROM DISK = N'\\TestServer\Transfer\PINK.bak'
WITH FILE = @backupSetId, NOUNLOAD, NOREWIND
GO
.bak
测试服务器上的内存大小根据您在 Explorer 中查看的位置而定,为 162GB 或 154GB :
.bak
为了节省空间,我尝试通过添加COMPRESSION
脚本来压缩:
BACKUP DATABASE [PINK]
TO DISK = N'\\TestServer\Transfer\PINK.bak'
WITH NOFORMAT, INIT, NAME = N'PINK', SKIP, NOREWIND, NOUNLOAD, COMPRESSION, STATS = 10, CHECKSUM
GO
DECLARE @backupSetId AS int
SELECT @backupSetId = position
FROM msdb..backupset
WHERE database_name = N'PINK'
AND backup_set_id = (SELECT MAX(backup_set_id)
FROM msdb..backupset
WHERE database_name = N'PINK')
IF @backupSetId IS NULL
BEGIN
RAISERROR(N'Verify failed. Backup information for database ''PINK'' not found.', 16, 1)
END
RESTORE VERIFYONLY
FROM DISK = N'\\TestServer\Transfer\PINK.bak'
WITH FILE = @backupSetId, NOUNLOAD, NOREWIND
GO
执行包含的命令后COMMPRESSION
,它在测试服务器上的大小相同。我检查了.ndf
和.mdf
文件,它们总共是 770GB 或 732GB,具体取决于您查看的位置。此外,它还包含大约 23GB 的索引信息。
.bak
尽管我没有声明要这么做,但这是否已经被压缩了?