From 979731f717573ac557390d5891d4674b9d484aeb Mon Sep 17 00:00:00 2001 From: Jerry Keselman Date: Wed, 1 Aug 2018 15:49:50 -0400 Subject: [PATCH 1/4] Support for DB Restore from Object Stores Support restore from an object store. --- lib/evm_database_ops.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/evm_database_ops.rb b/lib/evm_database_ops.rb index ee28eea60eb..d48e0fb4e6b 100644 --- a/lib/evm_database_ops.rb +++ b/lib/evm_database_ops.rb @@ -89,7 +89,8 @@ def self.restore(db_opts, connect_opts = {}) # :username => 'samba_one', # :password => 'Zug-drep5s', - uri = with_mount_session(:restore, db_opts, connect_opts) do |database_opts, _session, _remote_file_uri| + uri = with_mount_session(:restore, db_opts, connect_opts) do |database_opts, session, remote_file_uri| + database_opts[:local_file] = session.download(database_opts[:local_file], connect_opts[:remote_file_name]) if session prepare_for_restore(database_opts[:local_file]) # remove all the connections before we restore; AR will reconnect on the next query @@ -110,6 +111,7 @@ def self.restore(db_opts, connect_opts = {}) if db_opts[:local_file].nil? if action == :restore uri = connect_opts[:uri] + connect_opts[:remote_file_name] ||= connect_opts[:uri] connect_opts[:uri] = File.dirname(connect_opts[:uri]) else connect_opts[:remote_file_name] ||= File.basename(backup_file_name(action)) From ba83c9e65789e6431c2e18c6b561e051b63ca8f7 Mon Sep 17 00:00:00 2001 From: Jerry Keselman Date: Wed, 1 Aug 2018 16:11:49 -0400 Subject: [PATCH 2/4] Rubocop Warning --- lib/evm_database_ops.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/evm_database_ops.rb b/lib/evm_database_ops.rb index d48e0fb4e6b..d55b137421a 100644 --- a/lib/evm_database_ops.rb +++ b/lib/evm_database_ops.rb @@ -89,7 +89,7 @@ def self.restore(db_opts, connect_opts = {}) # :username => 'samba_one', # :password => 'Zug-drep5s', - uri = with_mount_session(:restore, db_opts, connect_opts) do |database_opts, session, remote_file_uri| + uri = with_mount_session(:restore, db_opts, connect_opts) do |database_opts, session, _remote_file_uri| database_opts[:local_file] = session.download(database_opts[:local_file], connect_opts[:remote_file_name]) if session prepare_for_restore(database_opts[:local_file]) From a4e4c7b0ed67a13614d0dec4dbbed4fefe1c679d Mon Sep 17 00:00:00 2001 From: Jerry Keselman Date: Thu, 2 Aug 2018 08:46:19 -0400 Subject: [PATCH 3/4] Use yielded remote_file_uri as argument to download Instead of overloading the connect opts by adding :remote_file_name use the already yielded remote_file_uri as the argument to the session.download call for restore. --- lib/evm_database_ops.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/evm_database_ops.rb b/lib/evm_database_ops.rb index d55b137421a..c2886581f7c 100644 --- a/lib/evm_database_ops.rb +++ b/lib/evm_database_ops.rb @@ -89,8 +89,8 @@ def self.restore(db_opts, connect_opts = {}) # :username => 'samba_one', # :password => 'Zug-drep5s', - uri = with_mount_session(:restore, db_opts, connect_opts) do |database_opts, session, _remote_file_uri| - database_opts[:local_file] = session.download(database_opts[:local_file], connect_opts[:remote_file_name]) if session + uri = with_mount_session(:restore, db_opts, connect_opts) do |database_opts, session, remote_file_uri| + database_opts[:local_file] = session.download(database_opts[:local_file], remote_file_uri) if session prepare_for_restore(database_opts[:local_file]) # remove all the connections before we restore; AR will reconnect on the next query @@ -111,7 +111,6 @@ def self.restore(db_opts, connect_opts = {}) if db_opts[:local_file].nil? if action == :restore uri = connect_opts[:uri] - connect_opts[:remote_file_name] ||= connect_opts[:uri] connect_opts[:uri] = File.dirname(connect_opts[:uri]) else connect_opts[:remote_file_name] ||= File.basename(backup_file_name(action)) From 8ee1edc6b0e8f9d62572447e58e86de925c34804 Mon Sep 17 00:00:00 2001 From: Jerry Keselman Date: Thu, 2 Aug 2018 10:20:35 -0400 Subject: [PATCH 4/4] Fix session download to only run when necessary Only run the download if the local file doesn't exist. --- lib/evm_database_ops.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/evm_database_ops.rb b/lib/evm_database_ops.rb index c2886581f7c..3eaaa7e02e6 100644 --- a/lib/evm_database_ops.rb +++ b/lib/evm_database_ops.rb @@ -90,7 +90,9 @@ def self.restore(db_opts, connect_opts = {}) # :password => 'Zug-drep5s', uri = with_mount_session(:restore, db_opts, connect_opts) do |database_opts, session, remote_file_uri| - database_opts[:local_file] = session.download(database_opts[:local_file], remote_file_uri) if session + if session && !File.exist?(database_opts[:local_file]) + database_opts[:local_file] = session.download(database_opts[:local_file], remote_file_uri) + end prepare_for_restore(database_opts[:local_file]) # remove all the connections before we restore; AR will reconnect on the next query