Arangorestore

To reload data from a dump previously created with arangodump,ArangoDB provides the arangorestore tool.

Please note that arangorestoremust not be used to create several similar database instances in one installation.

This means if you have an arangodump output of database a, and you create a second database bon the same instance of ArangoDB, and restore the dump of a into b - data integrity can notbe guaranteed.

Reloading Data into an ArangoDB database

Invoking arangorestore

arangorestore can be invoked from the command-line as follows:

  1. unix> arangorestore --input-directory "dump"

This will connect to an ArangoDB server and reload structural information and documents found in the input directory dump. Please note that the input directorymust have been created by running arangodump before.

arangorestore will by default connect to the _system database using the defaultendpoint. If you want to connect to a different database or a different endpoint, or use authentication, you can use the following command-line options:

  • —server.database : name of the database to connect to
  • —server.endpoint : endpoint to connect to
  • —server.username : username
  • —server.password : password to use (omit this and you'll be prompted for thepassword)
  • —server.authentication : whether or not to use authenticationSince version 2.6 arangorestore provides the option —create-database. Setting this option to true will create the target database if it does not exist. When creating thetarget database, the username and passwords passed to arangorestore (in options —server.username and —server.password) will be used to create an initial user for the new database.

The option —force-same-database allows restricting arangorestore operations to adatabase with the same name as in the source dump’s “dump.json” file. It can thus be usedto prevent restoring data into a “wrong” database by accident.

For example, if a dump was taken from database a, and the restore is attempted into database b, then with the —force-same-database option set to true, arangorestorewill abort instantly.

The —force-same-database option is set to false by default to ensure backwards-compatibility.

Here’s an example of reloading data to a non-standard endpoint, using a dedicateddatabase name:

  1. unix> arangorestore --server.endpoint tcp://192.168.173.13:8531 --server.username backup --server.database mydb --input-directory "dump"

To create the target database whe restoring, use a command like this:

  1. unix> arangorestore --server.username backup --server.database newdb --create-database true --input-directory "dump"

arangorestore will print out its progress while running, and will end with a lineshowing some aggregate statistics:

  1. Processed 2 collection(s), read 2256 byte(s) from datafiles, sent 2 batch(es)

By default, arangorestore will re-create all non-system collections found in the input directory and load data into them. If the target database already contains collections which are also present in the input directory, the existing collections in the database will be dropped and re-created with the data found in the input directory.

The following parameters are available to adjust this behavior:

  • —create-collection : set to true to create collections in the targetdatabase. If the target database already contains a collection with the same name,it will be dropped first and then re-created with the properties found in the inputdirectory. Set to false to keep existing collections in the target database. If set to false and arangorestore encounters a collection that is present in both the target database and the input directory, it will abort. The default value is true.
  • —import-data : set to true to load document data into the collections inthe target database. Set to false to not load any document data. The default value is true.
  • —include-system-collections : whether or not to include system collectionswhen re-creating collections or reloading data. The default value is false.For example, to (re-)create all non-system collections and load document data into them, use:
  1. unix> arangorestore --create-collection true --import-data true --input-directory "dump"

This will drop potentially existing collections in the target database that are also presentin the input directory.

To include system collections too, use —include-system-collections true:

  1. unix> arangorestore --create-collection true --import-data true --include-system-collections true --input-directory "dump"

To (re-)create all non-system collections without loading document data, use:

  1. unix> arangorestore --create-collection true --import-data false --input-directory "dump"

This will also drop existing collections in the target database that are also present in theinput directory.

To just load document data into all non-system collections, use:

  1. unix> arangorestore --create-collection false --import-data true --input-directory "dump"

To restrict reloading to just specific collections, there is is the —collection option.It can be specified multiple times if required:

  1. unix> arangorestore --collection myusers --collection myvalues --input-directory "dump"

Collections will be processed by in alphabetical order by arangorestore, with all documentcollections being processed before all edge collections. This is to ensure that reloadingdata into edge collections will have the document collections linked in edges (from_ andto_ attributes) loaded.

Encryption

See arangodump for details.

Reloading Data into a different Collection

arangorestore will restore document and edges data with the exact same key_, rev, __from and _to values as found in the input directory.

With some creativity you can also use arangodump and arangorestore to transfer data from onecollection into another (either on the same server or not). For example, to copy data froma collection myvalues in database mydb into a collection mycopyvalues in database mycopy,you can start with the following command:

  1. unix> arangodump --collection myvalues --server.database mydb --output-directory "dump"

This will create two files, myvalues.structure.json and myvalues.data.json, in the output directory. To load data from the datafile into an existing collection mycopyvalues in database mycopy, rename the files to mycopyvalues.structure.json and mycopyvalues.data.json.After that, run the following command:

  1. unix> arangorestore --collection mycopyvalues --server.database mycopy --input-directory "dump"

Using arangorestore with sharding

As of Version 2.1 the arangorestore tool supports sharding. Simplypoint it to one of the coordinators in your cluster and it willwork as usual but on sharded collections in the cluster.

If arangorestore is asked to restore a collection, it will use the same number of shards, replication factor and shard keys as when the collection was dumped. The distribution of the shards to the servers will also be the same as at the time of the dump,provided that the number of DBServers in the cluster dumped from is identical to thenumber of DBServers in the to-be-restored-to cluster.

To modify the number of shards or the replication factor for all or just some collections,arangorestore, starting from v3.3.22 and v3.4.2, provides the options —number-of-shards and —replication-factor.These options can be specified multiple times as well, in order to override the settingsfor dedicated collections, e.g.

  1. unix> arangorestore --number-of-shards 2 --number-of-shards mycollection=3 --number-of-shards test=4

The above will restore all collections except “mycollection” and “test” with 2 shards. “mycollection”will have 3 shards when restored, and “test” will have 4. It is possible to omit the default valueand only use collection-specific overrides. In this case, the number of shards for any collections notoverridden will be determined by looking into the “numberOfShards” values contained in the dump.

The —replication-factor options works in the same way, e.g.

  1. unix> arangorestore --replication-factor 2 --replication-factor mycollection=1

will set the replication factor to 2 for all collections but “mycollection”, which will get areplication factor of just 1.

If a collection was dumped from a single instance and is then restored intoa cluster, the sharding will be done by the _key attribute by default. One canmanually edit the structural description for the shard keys in the dump files ifrequired.

If you restore a collection that was dumped from a cluster into a singleArangoDB instance, the number of shards, replication factor and shard keys will silentlybe ignored.

Restoring collections with sharding prototypes

arangorestore will yield an error when trying to restore acollection whose shard distribution follows a collection which doesnot exist in the cluster and which was not dumped along:

  1. unix> arangorestore --collection clonedCollection --server.database mydb --input-directory "dump"
  2. ERROR got error from server: HTTP 500 (Internal Server Error): ArangoError 1486: must not have a distributeShardsLike attribute pointing to an unknown collection
  3. Processed 0 collection(s), read 0 byte(s) from datafiles, sent 0 batch(es)

The collection can be restored by overriding the error message asfollows:

  1. unix> arangorestore --collection clonedCollection --server.database mydb --input-directory "dump" --ignore-distribute-shards-like-errors

Restore into an authentication-enabled ArangoDB

Of course you can restore data into a password-protected ArangoDB as well.However this requires certain user rights for the user used in the restore process.The rights are described in detail in the Managing Users chapter.For restore this short overview is sufficient:

  • When importing into an existing database, the given user needs Administrate access on this database.
  • When creating a new Database during restore, the given user needs Administrate access on _system. The user will be promoted with Administrate access on the newly created database.