Skip to main content

Backup and restore

Example

#Backup and restore

To start or restore backup use StartBackup or StartRestore operations respectively.

Execution of the StartBackup and StartRestore methods simply starts the requested actions on the server and returns immediately. The StartBackup and StartRestore methods do not wait for operation to complete.

Task StartBackup(string backupLocation, FileSystemDocument fileSystemDocument, bool incremental, string fileSystemName);
Parameters
backupLocationstringThe path to a directory where the backup will be stored
fileSystemDocumentFileSystemDocumentThe file system configuration document that will be stored with the backup location as 'Filesystem.Document' file. Pass null to use the current one.<br />WARNING: The file system configuration document may contain sensitive data which will be decrypted and stored in the backup.
incrementalboolIndicates if it should be the incremental backup
fileSystemNamestringThe name of the file system to backup.

<hr/>

Return Value
TaskA task that represents the asynchronous start operation

Example

await store.AsyncFilesCommands.Admin
.StartBackup(@"C:\backups\NorthwindFS", null, false, "NorthwindFS");

If you are interested in checking the current backup status you can retrieve it by getting Raven/Backup/Status configuration item:

BackupStatus status = await store.AsyncFilesCommands.Configuration
.GetKeyAsync<BackupStatus>(BackupStatus.RavenBackupStatusDocumentKey);

if (status.IsRunning)
{
// ... //
}

StartRestore

Task<long> StartRestore(FilesystemRestoreRequest restoreRequest);
Parameters
restoreRequestFilesystemRestoreRequestRestore information

<hr/>

Return Value
Task<long>A task that represents the asynchronous restore operation. The task result is the operation identifier.

Example

long restoreOperationId = await store.AsyncFilesCommands.Admin
.StartRestore(new FilesystemRestoreRequest()
{
BackupLocation = @"C:\backups\NorthwindFS",
FilesystemLocation = @"~\FileSystems\NewNorthwindFS",
FilesystemName = "NewNorthwindFS"
});

If you needed to wait until the operation finishes, you would have to initialize DocumentStore associated with <system> database and wait for the operation completion:

using (var sysDbStore = new DocumentStore
{
Url = "http://localhost:8080/"
}.Initialize())
{
await new Operation((AsyncServerClient)sysDbStore.AsyncDatabaseCommands, restoreOperationId)
.WaitForCompletionAsync();
}