Skip to content

Instantly share code, notes, and snippets.

@solisoft
Last active February 5, 2019 17:23
Show Gist options
  • Save solisoft/ccf9365a639fb47f09c8c7f19cf8903b to your computer and use it in GitHub Desktop.
Save solisoft/ccf9365a639fb47f09c8c7f19cf8903b to your computer and use it in GitHub Desktop.
require 'net/http'
require 'json'
DB_USER_SRC = 'root'.freeze
DB_USER_DST = 'root'.freeze
DB_PASS_SRC = 'XXXX'.freeze
DB_PASS_DST = 'XXXX'.freeze
DB_ENDPOINT_SRC = 'http+tcp://0.0.0.0:8529'.freeze
DB_ENDPOINT_DST = 'http+tcp://0.0.0.0:9529'.freeze
DUMP_PATH = '/home/dump/'.freeze # must exist
DB_URL_SRC = 'http://0.0.0.0:8529'.freeze
DB_URL_DST = 'http://0.0.0.0:9529'.freeze
uri = URI(DB_URL_SRC + '/_api/database')
req = Net::HTTP::Get.new(uri)
req.basic_auth DB_USER_SRC, DB_PASS_SRC
res = Net::HTTP.start(uri.hostname, uri.port) {|http|
http.request(req)
}
results = JSON.parse(res.body)['result']
results.each do |result|
system("arangodump --output-directory #{DUMP_PATH}#{result} --server.endpoint #{DB_ENDPOINT_SRC} --server.username #{DB_USER_SRC} --server.password #{DB_PASS_SRC} --overwrite true --include-system-collections true --server.database #{result}")
system("arangorestore --server.database #{result} --server.endpoint #{DB_ENDPOINT_DST} --create-database true --include-system-collections true --input-directory #{DUMP_PATH}#{result} --server.password #{DB_PASS_DST}")
Dir.glob("/var/lib/arangodb3-apps/_db/#{result}/*").each do |app|
name = app.split("/").last
# I use foxx-cli
system("foxx install --server docker --database #{result} /#{name} /var/lib/arangodb3-apps/_db/#{result}/#{name}")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment