Article For
2.5 3.0 3.5 4.0 4.1 4.2 5.0 5.1 5.2 5.3

Bundle: Periodic Backup

RavenDB comes with support of doing periodic backup of documents and attachments to Amazon AWS services.
When creating a database in the studio you will see that you can't change the selection of the 'Periodic Backup Bundle' it's selection depends on the license.
In order to periodic backup to work you must activate PeriodicBackup bundle, by activating this bundle globally and turning it on/off per database, or activating it per database only.

How it works

Periodic backup are leveraging the concept of incremental backups available in RavenDB and to take advantage of that, we are storing an information about last successful ETag of the documents and attachments that were send to backup destination.


Activating bundle

To activate bundle globally just add PeriodicBackup to the Raven/ActiveBundles. More about setting up configuration can be found here.

If you wish to setup periodic backup per database, then add PeriodicBackup to the list of database active bundles or use the Studio.

Bundle can also be activated during database creation process.

store.DatabaseCommands.CreateDatabase(new DatabaseDocument
        Id = "BackupedDB",
        Settings =
                {"Raven/ActiveBundles", "PeriodicBackup"}

Configuring backup destination

Two steps need to be taken to setup backup destination properly.

First we need to add our AWS access and secret key to database settings. For example if we want to create new database with bundle already activated and keys setup, then we can execute following code:

store.DatabaseCommands.CreateDatabase(new DatabaseDocument
    Id = "BackupedDB",
    Settings =
                {"Raven/ActiveBundles", "PeriodicBackup"},
                {"Raven/AWSAccessKey", "<key_here>"}
    SecuredSettings =
                    {"Raven/AWSSecretKey", "<key_here>"}

In next step we need to create a backup setup document under Raven/Backup/Periodic/Setup where we will store our backup destination configuration. This document will be created automatically when you will use Studio to setup periodic backup, but it can be created almost as easily using the API.

                           RavenJObject.FromObject(new PeriodicBackupSetup
                                   AwsRegionEndpoint = "eu-west-1", // if not specified default is 'us-east-1'
                                   GlacierVaultName = "your_glacier_vault_name",
ntervalMilliseconds = 60 * 1000,
                                   S3BucketName = "your_s3_bucket_name"
                           new RavenJObject());

GlacierVaultName and S3BucketName values exclude each other in favor of the GlacierVaultName so if you will specify both, then RavenDB will only use GlacierVaultName.


More information about Amazon Simple Storage Service (Amazon S3) can be found here and if you are interested in Amazon Glacier then visit this page.

Restore from a periodic backup

The periodic backup is not a full backup really. It is, instead, an incremental export. To restore a database from a periodic backup you must user Raven.Smuggler.exe using the following syntax:

raven.smuggler.exe in http://localhost:8080 c:\path-to-folder --database=foo --incremental