Class: PgUtils::Restore
- Inherits:
-
Object
- Object
- PgUtils::Restore
- Defined in:
- lib/pg_utils/restore.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#local_database ⇒ Object
Returns the value of attribute local_database.
-
#local_database_password ⇒ Object
Returns the value of attribute local_database_password.
-
#local_database_username ⇒ Object
Returns the value of attribute local_database_username.
-
#local_folder ⇒ Object
Returns the value of attribute local_folder.
Instance Method Summary collapse
-
#initialize ⇒ Restore
constructor
A new instance of Restore.
- #run(filename = nil) ⇒ Object
Constructor Details
#initialize ⇒ Restore
Returns a new instance of Restore.
8 9 10 11 12 |
# File 'lib/pg_utils/restore.rb', line 8 def initialize() PgUtils.configuration.instance_variables.each do |k| instance_variable_set(k, PgUtils.configuration.instance_variable_get(k)) end end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
6 7 8 |
# File 'lib/pg_utils/restore.rb', line 6 def filename @filename end |
#local_database ⇒ Object
Returns the value of attribute local_database.
6 7 8 |
# File 'lib/pg_utils/restore.rb', line 6 def local_database @local_database end |
#local_database_password ⇒ Object
Returns the value of attribute local_database_password.
6 7 8 |
# File 'lib/pg_utils/restore.rb', line 6 def local_database_password @local_database_password end |
#local_database_username ⇒ Object
Returns the value of attribute local_database_username.
6 7 8 |
# File 'lib/pg_utils/restore.rb', line 6 def local_database_username @local_database_username end |
#local_folder ⇒ Object
Returns the value of attribute local_folder.
6 7 8 |
# File 'lib/pg_utils/restore.rb', line 6 def local_folder @local_folder end |
Instance Method Details
#run(filename = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/pg_utils/restore.rb', line 14 def run(filename = nil) if filename && filename.include?(".sql.gz") backup_file = "#{local_folder}/#{filename}" elsif !filename.nil? backup_file = "#{local_folder}/#{filename}.sql.gz" else backup_file = Dir.glob("#{local_folder}/*").max_by {|f| File.mtime(f)} end puts "restoring backup: #{backup_file}" exec_cmd = "PGPASSWORD=\"#{local_database_password}\" pg_restore -c -h localhost -U #{local_database_username} -Fc -d #{local_database} #{backup_file} --verbose" system(exec_cmd) end |