如何使用 ArangoDB 转储所有数据库
How to dump all databases with ArangoDB
我在本地有 ArangoDB 运行,里面有来自几个不同项目的数据库、集合、数据和图表。我想备份所有内容,以便重建我的系统。我知道如何备份单个数据库,但因为我有一堆,所以我希望一次性完成。
本质上,我正在寻找 ArangoDB 等同于
mysqldump -u root -p --all-databases > alldb.sql
显然 ArangoDB 相当于
mysql -u root -p < alldb.sql
也很高兴知道。
从 3.3 版开始,arangodump 不支持一次转储所有数据库。它是每个数据库。
要使其转储所有数据库,可以在所有数据库上循环调用它,例如
# 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
如果有一个用户拥有所有数据库的访问权限,这将起作用。
虽然前面的脚本几乎是正确的,但它不适用于多个数据库,因为它会开始抱怨转储目录,并要求您将 --overwrite true
添加到命令中。这也行不通,因为它只会输出最新的数据库。
我们使用以下脚本,它与 stj 的回答中的脚本略有不同(或者至少以下是备份过程的一部分)来获取我们拥有的所有数据库的转储:
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
我偶然发现了这个线程,看到有很多自定义解决方案。只是想提一下:
从 Arango v.3.5.0 开始,arangodump(以及 arangorestore)支持 --all-databases true
参数
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.
我在本地有 ArangoDB 运行,里面有来自几个不同项目的数据库、集合、数据和图表。我想备份所有内容,以便重建我的系统。我知道如何备份单个数据库,但因为我有一堆,所以我希望一次性完成。
本质上,我正在寻找 ArangoDB 等同于
mysqldump -u root -p --all-databases > alldb.sql
显然 ArangoDB 相当于
mysql -u root -p < alldb.sql
也很高兴知道。
从 3.3 版开始,arangodump 不支持一次转储所有数据库。它是每个数据库。
要使其转储所有数据库,可以在所有数据库上循环调用它,例如
# 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
如果有一个用户拥有所有数据库的访问权限,这将起作用。
虽然前面的脚本几乎是正确的,但它不适用于多个数据库,因为它会开始抱怨转储目录,并要求您将 --overwrite true
添加到命令中。这也行不通,因为它只会输出最新的数据库。
我们使用以下脚本,它与 stj 的回答中的脚本略有不同(或者至少以下是备份过程的一部分)来获取我们拥有的所有数据库的转储:
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
我偶然发现了这个线程,看到有很多自定义解决方案。只是想提一下:
从 Arango v.3.5.0 开始,arangodump(以及 arangorestore)支持 --all-databases true
参数
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.