Operations: Server: How to Restore a Database from the Backup
- To restore a database from its backup, use
RestoreBackupOperation
.
- A backup can also be restored using Studio.
Syntax
public RestoreBackupOperation(RestoreBackupConfiguration restoreConfiguration)
public class RestoreBackupConfiguration
{
public string DatabaseName { get; set; }
public string BackupLocation { get; set; }
public string LastFileNameToRestore { get; set; }
public string DataDirectory { get; set; }
public string EncryptionKey { get; set; }
}
Parameters |
|
|
DatabaseName |
string |
Database name to create during the restore operation |
BackupLocation |
string |
Directory containing backup files |
LastFileNameToRestore |
string |
Used for partial restore |
DataDirectory |
string |
Optional: Database data directory |
EncryptionKey |
string |
Encryption key used for restore |
Example
RestoreBackupConfiguration config = new RestoreBackupConfiguration()
{
BackupLocation = @"C:\backups\Northwind",
DatabaseName = "Northwind"
};
RestoreBackupOperation restoreOperation = new RestoreBackupOperation(config);
store.Maintenance.Server.Send(restoreOperation)
.WaitForCompletion();