据我所知,无法通过附加来做到这一点(因为附加要求所有文件都存在)。也看看这个答案。
虽然有替代方案。如果您的数据库处于完全恢复模式,您可以在没有文件流组的情况下进行部分备份。然后,您可以从该备份中恢复,任何丢失的文件组都将处于脱机模式且无法访问。任何尝试使用丢失文件组中的对象的查询都将失败。
示例命令:
BACKUP DATABASE [Demo]
FILEGROUP = N'PRIMARY'
TO DISK = N'.\MSSQL\Backup\Demo.bak'
WITH COPY_ONLY, NOFORMAT, NOINIT, NAME = N'Demo-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO
RESTORE DATABASE [OtherDatabase]
FILE = N'Demo' FROM DISK = N'.\MSSQL\Backup\Demo.bak' WITH FILE = 1,
MOVE N'Demo' TO N'.\MSSQL\DATA\OtherDatabase.mdf',
MOVE N'Demo_log' TO N'.\MSSQL\DATA\OtherDatabase_Log.ldf',
MOVE N'FStream' TO N'.\MSSQL\DATA\OtherDatabase_Documents', NOUNLOAD, STATS = 10
GO
编辑:
有关备份和恢复文件/文件组的一些其他有用链接:
编辑2:
如果您的数据库处于简单恢复模式并且您只想备份特定文件组,则必须将所有其他文件组设为只读。然后您可以使用 READ_WRITE_FILEGROUPS 仅备份 R/W 文件组。
示例命令:
USE [master]
GO
ALTER DATABASE [Demo] MODIFY FILEGROUP [FilestreamGroup] READONLY
GO
BACKUP DATABASE [Demo] READ_WRITE_FILEGROUPS TO DISK = N'.\MSSQL\Backup\EFCoreDemo.bak'
WITH COPY_ONLY, NOFORMAT, NOINIT, NAME = N'Demo-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO
ALTER DATABASE [Demo] MODIFY FILEGROUP [FilestreamGroup] READ_WRITE
GO
RESTORE DATABASE [OtherDatabase]
FILE = N'Demo' FROM DISK = N'.\MSSQL\Backup\EFCoreDemo.bak' WITH FILE = 1,
MOVE N'Demo' TO N'.\MSSQL\DATA\OtherDatabase.mdf',
MOVE N'Demo_log' TO N'.\MSSQL\DATA\OtherDatabase_Log.ldf',
MOVE N'FStream' TO N'.\MSSQL\DATA\OtherDatabase_Documents', NOUNLOAD, STATS = 10
GO