glacier_on_rails 0.9.9 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/application_database.rb +10 -2
- data/app/models/application_database/postgres_adapter.rb +3 -19
- data/app/models/glacier_db_archive.rb +0 -6
- data/app/models/pg_pass.rb +24 -0
- data/db/migrate/20170503133854_create_glacier_archives_table.rb +1 -1
- data/db/migrate/20170602135721_create_application_data_backups.rb +1 -1
- data/db/migrate/20170602145526_create_glacier_file_archive_join_table.rb +1 -1
- data/glacier_on_rails.gemspec +2 -2
- data/lib/tasks/aws.rake +1 -0
- data/spec/features/application_data_backup_spec.rb +2 -2
- data/spec/models/pg_pass_spec.rb +7 -0
- data/spec/models/postgres_adapter_spec.rb +4 -4
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c3545972de61ff80f578bb26a1e4d3df5b889e4
|
4
|
+
data.tar.gz: 707c970982ccdc1c57d22f2bcdf9710d9ec4159b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10246ae2a0d64d9b0df6bbf01bd90cbfd22392eda37f7a3f37ffcf1335de0decf8331a6155d19967fc9ecc794d9528db24e02c95a9311aa8ac801d56db594f77
|
7
|
+
data.tar.gz: 5bd6139d008f6c6cfa4417dbbb88b2758cb3bf2e3df5ea26726fdf10ec2daa3d6d40198ba732f8e3bef794408b7ffd542546b6414de97ffdaf4679f9b03a1e85
|
@@ -1,8 +1,14 @@
|
|
1
1
|
class ApplicationDatabase
|
2
|
-
class
|
2
|
+
class ConfigurationError < StandardError
|
3
|
+
def initialize(message)
|
4
|
+
AwsLog.error "#{self.class.name} exception: #{message}"
|
5
|
+
super
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class MissingConfigurationKeys < ConfigurationError
|
3
10
|
def initialize(missing_keys)
|
4
11
|
message = "#{missing_keys.join(' and ')} must be specified in config/database.yml"
|
5
|
-
AwsLog.error "ApplicationDatabase::MissingConfigurationKeys exception: #{message}"
|
6
12
|
super(message)
|
7
13
|
end
|
8
14
|
end
|
@@ -17,6 +23,8 @@ class ApplicationDatabase
|
|
17
23
|
when "mysql"
|
18
24
|
MysqlAdapter.new(db_config)
|
19
25
|
end
|
26
|
+
rescue ConfigurationError
|
27
|
+
@adapter = Struct.new(:contents).new(nil)
|
20
28
|
end
|
21
29
|
|
22
30
|
def db_config
|
@@ -2,20 +2,6 @@ class ApplicationDatabase::PostgresAdapter < ApplicationDatabase::BaseAdapter
|
|
2
2
|
class PgDumpCmdMissing < StandardError; end
|
3
3
|
class PgRestoreCmdMissing < StandardError; end
|
4
4
|
class PgRestoreFileMissing < StandardError; end
|
5
|
-
class PgPassFileMissing < StandardError
|
6
|
-
def initialize
|
7
|
-
message = "#{File.expand_path("~/.pgpass")} file not found, cannot dump database contents"
|
8
|
-
AwsLog.error "ApplicationDatabase::PostgresAdapter::PgPassFileMissing exception: #{message}"
|
9
|
-
super(message)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
class PgPassFilePermissionsError < StandardError
|
13
|
-
def initialize
|
14
|
-
message = "password file #{File.expand_path("~/.pgpass")} has group or world access; permissions should be u=rw (0600)"
|
15
|
-
AwsLog.error "ApplicationDatabase::PostgresAdapter::PgPassFilePermissionsError exception: #{message}"
|
16
|
-
super(message)
|
17
|
-
end
|
18
|
-
end
|
19
5
|
|
20
6
|
RestoreExclusions = %w{ application_data_backups
|
21
7
|
glacier_archives
|
@@ -24,12 +10,10 @@ class ApplicationDatabase::PostgresAdapter < ApplicationDatabase::BaseAdapter
|
|
24
10
|
RestoreList = GlacierArchive::BackupFileDir.join('restore.list')
|
25
11
|
|
26
12
|
def contents
|
27
|
-
if db_config["password"].present?
|
28
|
-
password_file = File.expand_path("~/.pgpass")
|
29
|
-
raise PgPassFileMissing unless File.exists?(password_file)
|
30
|
-
raise PgPassFilePermissionsError unless sprintf("%o", File.stat(password_file).mode) =~ /600$/
|
31
|
-
end
|
13
|
+
PgPass.ensure if db_config["password"].present?
|
32
14
|
`#{pg_dump} -w -Fc -U #{db_config['username']} #{db_config['database']}`
|
15
|
+
rescue ApplicationDatabase::ConfigurationError
|
16
|
+
nil
|
33
17
|
end
|
34
18
|
|
35
19
|
def restore(file)
|
@@ -11,12 +11,6 @@ class GlacierDbArchive < GlacierArchive
|
|
11
11
|
|
12
12
|
def archive_contents
|
13
13
|
ApplicationDatabase.new.contents
|
14
|
-
rescue ApplicationDatabase::PostgresAdapter::PgPassFilePermissionsError
|
15
|
-
nil
|
16
|
-
rescue ApplicationDatabase::PostgresAdapter::PgPassFileMissing
|
17
|
-
nil
|
18
|
-
rescue ApplicationDatabase::MissingConfigurationKeys
|
19
|
-
nil
|
20
14
|
end
|
21
15
|
|
22
16
|
# for file archive, true inhibits fetching archive from AWS
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class PgPass
|
2
|
+
|
3
|
+
class FileMissing < ApplicationDatabase::ConfigurationError
|
4
|
+
def initialize
|
5
|
+
message = "#{File.expand_path("~/.pgpass")} file not found, cannot dump database contents"
|
6
|
+
super(message)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class FilePermissionsError < ApplicationDatabase::ConfigurationError
|
11
|
+
def initialize
|
12
|
+
message = "password file #{File.expand_path("~/.pgpass")} has group or world access; permissions should be u=rw (0600)"
|
13
|
+
super(message)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.ensure
|
18
|
+
# TODO missing file and permissions errors are recoverable
|
19
|
+
# create or chmod the file instead of triggering an exception
|
20
|
+
password_file = File.expand_path("~/.pgpass")
|
21
|
+
raise FileMissing unless File.exists?(password_file)
|
22
|
+
raise FilePermissionsError unless sprintf("%o", File.stat(password_file).mode) =~ /600$/
|
23
|
+
end
|
24
|
+
end
|
data/glacier_on_rails.gemspec
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "glacier_on_rails"
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "1.0.0"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.authors = ["Les Nightingill"]
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.rubygems_version = "2.1.11"
|
16
16
|
s.summary = "database backup/restore utilities"
|
17
17
|
|
18
|
-
s.add_runtime_dependency "rails", "~>
|
18
|
+
s.add_runtime_dependency "rails", "~> 6.0.0rc1"
|
19
19
|
s.add_runtime_dependency "httparty", "~> 0.15.5"
|
20
20
|
s.add_development_dependency "byebug", "~> 9.0", ">= 9.0.6"
|
21
21
|
s.add_development_dependency("capybara", "~> 2.4")
|
data/lib/tasks/aws.rake
CHANGED
@@ -192,7 +192,7 @@ feature "backup_now", :js => true do
|
|
192
192
|
expect{page.find('#backup_now').click; wait_for_ajax}.not_to change{ApplicationDataBackup.count}
|
193
193
|
expect(page).not_to have_selector("#application_data_backups .application_data_backup")
|
194
194
|
expect(flash_message).to eq "failed to create backup"
|
195
|
-
expect(aws_log).to match /
|
195
|
+
expect(aws_log).to match /PgPass::FileMissing exception: #{File.expand_path("~/.pgpass")} file not found, cannot dump database contents/
|
196
196
|
end
|
197
197
|
end
|
198
198
|
|
@@ -215,7 +215,7 @@ feature "backup_now", :js => true do
|
|
215
215
|
expect{page.find('#backup_now').click; wait_for_ajax}.not_to change{ApplicationDataBackup.count}
|
216
216
|
expect(page).not_to have_selector("#application_data_backups .application_data_backup")
|
217
217
|
expect(flash_message).to eq "failed to create backup"
|
218
|
-
expect(aws_log).to match /#{Regexp.escape
|
218
|
+
expect(aws_log).to match /#{Regexp.escape PgPass::FilePermissionsError.new.message}/
|
219
219
|
end
|
220
220
|
end
|
221
221
|
end
|
@@ -28,8 +28,8 @@ describe "PostgresAdapter#contents dependence on password file ~/.pgpass" do
|
|
28
28
|
allow(File).to receive(:exists?).with(File.expand_path("~/.pgpass")).and_return(false)
|
29
29
|
end
|
30
30
|
|
31
|
-
it "should
|
32
|
-
expect
|
31
|
+
it "should be nil" do
|
32
|
+
expect( ApplicationDatabase.new.contents ).to be_nil
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -58,8 +58,8 @@ describe "PostgresAdapter#contents dependence on password file ~/.pgpass" do
|
|
58
58
|
allow(File).to receive(:stat).with(File.expand_path("~/.pgpass")).and_return(status)
|
59
59
|
end
|
60
60
|
|
61
|
-
it "should
|
62
|
-
expect
|
61
|
+
it "should be nil" do
|
62
|
+
expect(ApplicationDatabase.new.contents).to be_nil
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glacier_on_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Les Nightingill
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.0.0rc1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 6.0.0rc1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: httparty
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,6 +192,7 @@ files:
|
|
192
192
|
- app/models/glacier_archive.rb
|
193
193
|
- app/models/glacier_db_archive.rb
|
194
194
|
- app/models/glacier_file_archive.rb
|
195
|
+
- app/models/pg_pass.rb
|
195
196
|
- app/views/glacier_on_rails/aws_archive_retrieval_jobs/_application_data_backup.haml
|
196
197
|
- app/views/glacier_on_rails/aws_archive_retrieval_jobs/_available.haml
|
197
198
|
- app/views/glacier_on_rails/aws_archive_retrieval_jobs/_index.haml
|
@@ -267,6 +268,7 @@ files:
|
|
267
268
|
- spec/models/application_file_spec.rb
|
268
269
|
- spec/models/glacier_db_archive_spec.rb
|
269
270
|
- spec/models/glacier_file_archive_spec.rb
|
271
|
+
- spec/models/pg_pass_spec.rb
|
270
272
|
- spec/models/postgres_adapter_spec.rb
|
271
273
|
- spec/rails_helper.rb
|
272
274
|
- spec/spec_helper.rb
|