简体   繁体   中英

How to dump all databases with ArangoDB

I have ArangoDB running locally with databases, collections, data and graphs from several different projects in it. I'd like to back up everything so I can rebuild my system. I know how to do a backup of a single database, but because I have a bunch I'm hoping to do this in one shot.

Essentially, I'm looking for the ArangoDB equivalent of

mysqldump -u root -p --all-databases > alldb.sql

Obviously the ArangoDB equivalent of

mysql -u root -p < alldb.sql

Would be good to know too.

As of release 3.3, arangodump does not support dumping all databases at once. It is per database.

To make it dump all databases, it can be invoked in a loop over all databases, eg

# loop over all databases
for db in `arangosh --javascript.execute-string "db._databases().forEach(function(db) { print(db); });"` # host, user and password go here...
  do
    arangodump --sever.database "$db" # host, user and password go here...
  done

This will work if there is one user that has access privileges for all databases.

While the previous script is almost correct, it won't work with multiple database, since it will start complaining about the dump directory, and asks you to add --overwrite true to the command. This won't work as well, since it'll only output the latest database.

We use the following script, which is slightly changed from the one from stj's answer (or at least the following is part of the backup procedure) to get a dump of all the databases we have:

USER=...
PASSWORD=...
for db in $(arangosh --server.username "$USER" --server.password "$PASSWORD" --javascript.execute-string "db._databases().forEach(function(db) { print(db); });")
do
  arangodump --output-directory ~/dump/"$db" --overwrite true --server.username "$USER" --server.password "$PASSWORD" --server.database "$db" 
done

I came across this thread and saw that there are a bunch of custom solutions. Just wanted to mention that:

As of Arango v.3.5.0, arangodump (as well as arangorestore) support the --all-databases true parameter

arangodump got an option --all-databases to make it dump all available databases instead of just a single database specified via the option --server.database.

When set to true, this makes arangodump dump all available databases the current user has access to. The option --all-databases cannot be used in combination with the option --server.database.

When --all-databases is used, arangodump will create a subdirectory with the data of each dumped database. Databases will be dumped one after the after. However, inside each database, the collections of the database can be dumped in parallel using multiple threads. When dumping all databases, the consistency guarantees of arangodump are the same as when dumping multiple single database individually, so the dump does not provide cross-database consistency of the data.

arangorestore got an option --all-databases to make it restore all databases from inside the subdirectories of the specified dump directory, instead of just the single database specified via the option --server.database.

Using the option for arangorestore only makes sense for dumps created with arangodump and the --all-databases option. As for arangodump, arangorestore cannot be invoked with the both options --all-databases and --server.database at the same time. Additionally, the option --force-same-database cannot be used together with --all-databases.

If the to-be-restored databases do not exist on the target server, then restoring data into them will fail unless the option --create-database is also specified for arangorestore. Please note that in this case a database user must be used that has access to the _system database, in order to create the databases on restore.

Reference: https://www.arangodb.com/docs/stable/release-notes-new-features35.html#dump-and-restore-all-databases

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM