使用 C# 和SMO,如何向 SQL Server 添加备份设备?

发布于 2024-08-25 15:34:35 字数 778 浏览 4 评论 0原文

我知道如何使用 C# 和 SMO 在 SQL Server 上创建文件备份:

public void BackupDatabase(Microsoft.SqlServer.Management.Smo.Server server, 
                               string databaseName, string backupFilename,
                               string backupName, string backupDescription) {

 Backup backup = new Backup();
 backup.Devices.AddDevice(backupFilename, DeviceType.File);
 backup.Database = databaseName;
 backup.Action = BackupActionType.Database;
 backup.BackupSetDescription = backupDescription;
 backup.BackupSetName = backupName;
 backup.Incremental = false;
 backup.LogTruncation = BackupTruncateLogType.Truncate;
 backup.Initialize = true; // supposed to overwrite
 backup.SqlBackup(server);
}

我不知道(也找不到)的是如何将文件 BackupDevice 添加到 SQL Server。

I know how to use C# and SMO to create a file backup on a SQL Server:

public void BackupDatabase(Microsoft.SqlServer.Management.Smo.Server server, 
                               string databaseName, string backupFilename,
                               string backupName, string backupDescription) {

 Backup backup = new Backup();
 backup.Devices.AddDevice(backupFilename, DeviceType.File);
 backup.Database = databaseName;
 backup.Action = BackupActionType.Database;
 backup.BackupSetDescription = backupDescription;
 backup.BackupSetName = backupName;
 backup.Incremental = false;
 backup.LogTruncation = BackupTruncateLogType.Truncate;
 backup.Initialize = true; // supposed to overwrite
 backup.SqlBackup(server);
}

What I don't know (and can't find) is how to add the file BackupDevice to the SQL server.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那小子欠揍 2024-09-01 15:34:35

使用备份设备。创建

Server server = new Server("localhost");
BackupDevice newDevice = new BackupDevice();
newDevice.Parent = server;
newDevice.Name = "newDevice";
newDevice.BackupDeviceType = BackupDeviceType.Disk;
newDevice.PhysicalLocation = "c:\temp\newdevice.bak";
newDevice.Create();

Use BackupDevice.Create:

Server server = new Server("localhost");
BackupDevice newDevice = new BackupDevice();
newDevice.Parent = server;
newDevice.Name = "newDevice";
newDevice.BackupDeviceType = BackupDeviceType.Disk;
newDevice.PhysicalLocation = "c:\temp\newdevice.bak";
newDevice.Create();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文