我創建了一個腳本來備份和恢復我的sql數據庫。我最近剛搬到Azure Sql Server。以下我的備份策略不再有效。對於我的程序,它通常會保存備份並創建一個名爲training的後綴。看來Azure Sql Server的備份策略是完全不同的。請問如何以編程方式備份Azure Sql數據庫並將其還原。以編程方式備份Azure Sql db
if (!sqlServer.Databases.Contains(databaseTraining))
{
var backupFile = string.Concat(sqlServer.Settings.BackupDirectory, "\\", database, "Training.BAK");
var sourceBackup = new Backup
{
Database = database,
Action = BackupActionType.Database
};
var destDevice = new BackupDeviceItem(backupFile, DeviceType.File);
sourceBackup.Devices.Add(destDevice);
sourceBackup.Initialize = true;
sourceBackup.SqlBackup(sqlServer);
var db = new Microsoft.SqlServer.Management.Smo.Database(sqlServer, databaseTraining);
db.Create();
var destinationRestore = new Restore
{
Database = databaseTraining,
Action = RestoreActionType.Database
};
destinationRestore.Devices.Add(destDevice);
var dataFile = new RelocateFile
{
LogicalFileName = destinationRestore.ReadFileList(sqlServer).Rows[0][0].ToString(),
PhysicalFileName = sqlServer.Databases[databaseTraining].FileGroups[0].Files[0].FileName
};
var logFile = new RelocateFile
{
LogicalFileName = destinationRestore.ReadFileList(sqlServer).Rows[1][0].ToString(),
PhysicalFileName = sqlServer.Databases[databaseTraining].LogFiles[0].FileName
};
destinationRestore.RelocateFiles.Add(dataFile);
destinationRestore.RelocateFiles.Add(logFile);
destinationRestore.ReplaceDatabase = true;
destinationRestore.NoRecovery = false;
destinationRestore.SqlRestore(sqlServer);
這是不同的:MS做備份,而不是你。 ['BACKUP'](https://msdn.microsoft.com/en-us/library/ms186865.aspx?f=255&MSPPError=-2147217396)命令在Azure SQL Server上不可用。 – Richard
對於SQL Azure,您可能需要查看專業備份服務,如[CloudBerry](http://www.cloudberrylab.com/),[RedGate的CherrySafe](https://www.cherrysafe.com/)。 – Win