pg_drive_backup 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 02b992847439cdf0579b8a2266b3388f56a045f0
4
+ data.tar.gz: ca2c38d42d80a217c7928c36439e8d6909fe8f59
5
+ SHA512:
6
+ metadata.gz: 04d55bec48cff495104c9962328d713b9cbf205d54e85dbbaf861a8b5c3832e2e27440513e68c3315e80a10a86a4bdba9c06dd707e953e0b360639c32f27aff4
7
+ data.tar.gz: 01c8e460d47f2696f232478ef95dc6933166304ac9c785cd822043f2637f86a7b2b2f2e428c165ea656cd0f9dc8a0a8c67daa8bf004bcd003b55b6e9d05d4427
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,21 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ DisplayStyleGuide: true
4
+ StyleGuideCopsOnly: true
5
+ TargetRubyVersion: 2.4
6
+
7
+ Metrics/LineLength:
8
+ Max: 120
9
+
10
+ Documentation:
11
+ Enabled: false
12
+
13
+ FrozenStringLiteralComment:
14
+ Enabled: false
15
+
16
+ Style/FileName:
17
+ Enabled: false
18
+
19
+ Metrics/ModuleLength:
20
+ Exclude:
21
+ - spec/**/*_spec.rb
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in pg_drive_backup.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Kirill Shevchenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # PgDriveBackup
2
+
3
+ Simple solution to make encrypted with [ccrypt](http://ccrypt.sourceforge.net/) PostgreSQL backups with storing on [Google Drive API](https://github.com/gimite/google-drive-ruby)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'pg_drive_backup'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install pg_drive_backup
20
+
21
+ ## Usage
22
+
23
+ ### Quick start
24
+
25
+ Required database config credentials:
26
+
27
+ `config/initializers/pg_drive_backup.rb`
28
+ ```ruby
29
+ PgDriveBackup::Settings.configure do |config|
30
+ config.database.name = 'database_name'
31
+ config.database.user = ENV.fetch('PG_USERNAME')
32
+ config.database.password = ENV.fetch('PG_PASSWORD')
33
+ end
34
+ ```
35
+
36
+ Add your google drive [authorization](https://github.com/gimite/google-drive-ruby/blob/master/doc/authorization.md) JSON file to `config/drive.json`
37
+
38
+ Generate your encryption key, for example:
39
+ ```bash
40
+ openssl passwd -1 "somepassword"
41
+ ```
42
+
43
+ And put it into `config/key.txt`
44
+
45
+ Run it:
46
+ ```ruby
47
+ PgDriveBackup::Run.call
48
+ ```
49
+
50
+ It uploads your encrypted backup with name like `20171009083306693-dump.sql.cpt`
51
+
52
+ To decrypt:
53
+ ```bash
54
+ ccrypt -k config/key.txt -d 20171009083306693-dump.sql.cpt
55
+ ```
56
+
57
+ ### Tunning
58
+
59
+ Config options:
60
+
61
+ ```ruby
62
+ PgDriveBackup::Settings.configure do |config|
63
+ config.credentials_path = 'config/drive.json' # default: 'config/drive.json'
64
+ config.key_path = 'config/key.txt' # default: 'config/key.txt'
65
+ config.prefix = '-dump' # default: '-dump'
66
+
67
+ config.database.name = 'database_name' # default: nil
68
+ config.database.user = ENV.fetch('PG_USERNAME') # default: nil
69
+ config.database.password = ENV.fetch('PG_PASSWORD') # default: nil
70
+ config.database.host = 'localhost' # default: 'localhost'
71
+ end
72
+ ```
73
+
74
+ ## Contributing
75
+
76
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kirillshevch/pg_drive_backup.
77
+
78
+ ## License
79
+
80
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/circle.yml ADDED
File without changes
@@ -0,0 +1,22 @@
1
+ module PgDriveBackup
2
+ class Run
3
+ def self.call
4
+ config = Settings.config
5
+
6
+ filename = Time.now.strftime('%Y%m%d%H%M%S%L') + config.prefix
7
+
8
+ system("PGPASSWORD=#{config.database.password}
9
+ pg_dump #{config.database.name} > #{filename}.sql
10
+ -h #{config.database.host}
11
+ -U #{config.database.user}")
12
+
13
+ system("ccrypt -k #{config.key_path} -e #{filename}.sql")
14
+
15
+ session = GoogleDrive::Session.from_service_account_key(config.credentials_path)
16
+
17
+ if session.upload_from_file("#{filename}.sql.cpt")
18
+ system("rm -r #{filename}.sql.cpt")
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ module PgDriveBackup
2
+ class Settings
3
+ extend ::Dry::Configurable
4
+
5
+ setting :credentials_path, 'config/drive.json'
6
+
7
+ setting :key_path, 'config/key.txt'
8
+
9
+ setting :prefix, '-dump'
10
+
11
+ setting :database do
12
+ setting :name
13
+ setting :user
14
+ setting :password
15
+ setting :host, 'localhost'
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module PgDriveBackup
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'dry-configurable'
2
+ require 'google_drive'
3
+ require 'pg_drive_backup/version'
4
+ require 'pg_drive_backup/settings'
5
+ require 'pg_drive_backup/run'
@@ -0,0 +1,34 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ # coding: utf-8
5
+
6
+ lib = File.expand_path('../lib', __FILE__)
7
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
8
+ require 'pg_drive_backup/version'
9
+
10
+ Gem::Specification.new do |spec|
11
+ spec.name = 'pg_drive_backup'
12
+ spec.version = PgDriveBackup::VERSION
13
+ spec.authors = ['Kirill Shevchenko']
14
+ spec.email = ['hello@kirillshevch.com']
15
+
16
+ spec.summary = 'PostgreSQL backups with ccrypt to Google Drive API'
17
+ spec.description = 'Simple solution to make encrypted with ccrypt PostgreSQL backups with storing on Google Drive API'
18
+ spec.homepage = 'https://github.com/kirillshevch/pg_drive_backup'
19
+ spec.license = 'MIT'
20
+
21
+ spec.files = `git ls-files -z`.split("\x0")
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_dependency 'google_drive', '~> 2.1.6'
27
+ spec.add_dependency 'dry-configurable', '~> 0.7'
28
+
29
+ spec.add_development_dependency 'bundler', '~> 1.14'
30
+ spec.add_development_dependency 'rake', '~> 12.0'
31
+ spec.add_development_dependency 'rspec', '~> 3.6'
32
+ spec.add_development_dependency 'byebug', '~> 9.1.0'
33
+ spec.add_development_dependency 'rubocop', '~> 0.50.0'
34
+ end
@@ -0,0 +1,17 @@
1
+ describe PgDriveBackup::Settings do
2
+ subject { PgDriveBackup::Settings.config }
3
+
4
+ context 'has default settings' do
5
+ it { expect(subject.credentials_path).to eq('config/drive.json') }
6
+ it { expect(subject.key_path).to eq('config/key.txt') }
7
+ it { expect(subject.prefix).to eq('-dump') }
8
+
9
+ it { expect(subject.database.host).to eq('localhost') }
10
+ end
11
+
12
+ context 'has not default database credentials' do
13
+ it { expect(subject.database.name).to be_nil }
14
+ it { expect(subject.database.user).to be_nil }
15
+ it { expect(subject.database.password).to be_nil }
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ describe PgDriveBackup do
2
+ it 'has a version number' do
3
+ expect(PgDriveBackup::VERSION).not_to be nil
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ require 'bundler/setup'
2
+ require 'byebug'
3
+ require 'pg_drive_backup'
4
+
5
+ RSpec.configure do |config|
6
+ config.order = :random
7
+ config.filter_run focus: true
8
+ config.run_all_when_everything_filtered = true
9
+
10
+ config.expect_with :rspec do |c|
11
+ c.syntax = :expect
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pg_drive_backup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kirill Shevchenko
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-10-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: google_drive
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-configurable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 9.1.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 9.1.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.50.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.50.0
111
+ description: Simple solution to make encrypted with ccrypt PostgreSQL backups with
112
+ storing on Google Drive API
113
+ email:
114
+ - hello@kirillshevch.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".rubocop.yml"
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - circle.yml
127
+ - lib/pg_drive_backup.rb
128
+ - lib/pg_drive_backup/run.rb
129
+ - lib/pg_drive_backup/settings.rb
130
+ - lib/pg_drive_backup/version.rb
131
+ - pg_drive_backup.gemspec
132
+ - spec/pg_drive_backup/settings_spec.rb
133
+ - spec/pg_drive_backup_spec.rb
134
+ - spec/spec_helper.rb
135
+ homepage: https://github.com/kirillshevch/pg_drive_backup
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.5.2
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: PostgreSQL backups with ccrypt to Google Drive API
159
+ test_files: []