我知道如何使用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服务器。
答案 0 :(得分:6)
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();