ArangoDB-备份和还原所有数据

时间:2019-05-28 09:17:07

标签: arangodb

我的目的是创建arango数据库转储(包含所有用户和密码,权限,数据库,集合,角色等),然后在另一台arango服务器(从从头开始并为空)。

我使用的是单节点配置,arangodb版本为 3.4.4 [linux]

最初,我会转储每个数据库:

USER=root
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 /tmp/dump/"$db" --overwrite true --server.username "$USER" --server.password "$PASSWORD" --include-system-collections --server.database "$db"
done

然后我将创建的文件夹移动到该服务器上的空arangodb服务器,并执行以下操作:

arangorestore --input-directory "/tmp/dump/_system/"
arangorestore --input-directory "/tmp/dump/collection/"
arangorestore --input-directory "/tmp/dump/collection2/"
...one by one 

如果结果超出了我的期望,我只是在 _system 数据库中为 root 用户(没有其他用户,没有数据库)获得了集合。

我在做什么错?如何进行完整备份和还原?

谢谢。

1 个答案:

答案 0 :(得分:2)

arangorestore需要告知要将数据还原到哪个数据库。这可以通过提供--server.database选项的方式与对arangodump所做的方式相同来实现。 如果没有为--server.database提供任何值,它将默认为_system,这意味着随后的arangorestore调用将分别覆盖_system数据库中的先前数据。

如果目标数据库在备份服务器上尚不存在,则可以使用选项--create-database true即时创建它们。 此外,要还原系统集合,需要为arangorestore提供选项--include-system-collections true

这意味着,如果您的数据库确实名为“ collection”和“ collection2”,则还原命令应如下所示:

arangorestore --input-directory "/tmp/dump/_system/" --server.database "_system" --include-system-collections true --create-database true
arangorestore --input-directory "/tmp/dump/collection/" --server.database "collection" --include-system-collections true --create-database true
arangorestore --input-directory "/tmp/dump/collection2/" --server.database "collection2" --include-system-collections true --create-database true

还请注意,对于AranggoDB 3.5,arangodump和arangorestore都有一个选项--all-databases,这将大大简化备份和还原过程。