rubypond-s3backup-manager 0.1.01 → 0.1.02

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,17 +17,21 @@ module S3BackupManager
17
17
  [directory]
18
18
  end
19
19
 
20
- def restore_database_from_file(username, database, filename)
21
- # `psql -h localhost -d postgres -U postgres -f "/path/to/useraccts.sql" `
22
- # exit(1) unless $?.success?
23
- `sudo -u #{username} pg_restore --format=t -d #{database} #{filename}`
20
+ def restore_database_from_file(username, database, directory)
21
+ directory = "#{directory}/tmp/#{database}/s3postgresbackup/#{database}"
22
+ user_file = "#{directory}/globals.pgsql"
23
+ system "cd /tmp && sudo -u #{username} psql -f #{user_file} >/dev/null 2>&1"
24
+ exit(1) unless $?.success?
25
+ dump_file = "#{directory}/#{database}.pgsql"
26
+ recreate_database!(username, database)
27
+ system "cd /tmp && sudo -u #{username} pg_restore --format=t -d #{database} #{dump_file} >/dev/null 2>&1"
24
28
  exit(1) unless $?.success?
25
29
  end
26
30
 
27
31
  private
28
- def recreate_database(database)
29
- `sudo -u postgres dropdb #{database}`
30
- `sudo -u postgres createdb --encoding=UNICODE #{database}`
32
+ def recreate_database!(username, database)
33
+ system "cd /tmp && sudo -u #{username} dropdb #{database}"
34
+ system "cd /tmp && sudo -u #{username} createdb --encoding=UNICODE #{database}"
31
35
  end
32
36
 
33
37
  end
@@ -31,14 +31,14 @@ module S3BackupManager
31
31
  filename = "#{@options[:adapter]}/#{timestamp}/#{database}"
32
32
  @dumped_filename = "/tmp/#{random_string}"
33
33
  super(filename, timestamp, @dumped_filename, "databases")
34
- restore_database_from_file(@options[:username], database, "#{@dumped_filename}/tmp/#{database}")
34
+ restore_database_from_file(@options[:username], database, @dumped_filename)
35
35
  db_cleanup!
36
36
  end
37
37
 
38
38
  private
39
39
  def db_cleanup!
40
40
  if @dumped_filename
41
- File.delete(@dumped_filename)
41
+ FileUtils.rm_r(@dumped_filename)
42
42
  @dumped_filename = nil
43
43
  end
44
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubypond-s3backup-manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.01
4
+ version: 0.1.02
5
5
  platform: ruby
6
6
  authors:
7
7
  - Glenn Gillen