backy_rb 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/.drone.yml +13 -0
  3. data/.idea/.gitignore +8 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +23 -0
  6. data/CHANGELOG.md +5 -0
  7. data/Gemfile +16 -0
  8. data/Gemfile.lock +120 -0
  9. data/README.md +36 -0
  10. data/Rakefile +10 -0
  11. data/backy.gemspec +45 -0
  12. data/bucky.png +0 -0
  13. data/config/database.example.yml +15 -0
  14. data/dummy/psql/.gitattributes +7 -0
  15. data/dummy/psql/.gitignore +22 -0
  16. data/dummy/psql/.ruby-version +1 -0
  17. data/dummy/psql/Gemfile +34 -0
  18. data/dummy/psql/Gemfile.lock +207 -0
  19. data/dummy/psql/README.md +24 -0
  20. data/dummy/psql/Rakefile +6 -0
  21. data/dummy/psql/app/assets/config/manifest.js +2 -0
  22. data/dummy/psql/app/assets/images/.keep +0 -0
  23. data/dummy/psql/app/assets/stylesheets/application.css +15 -0
  24. data/dummy/psql/app/controllers/application_controller.rb +2 -0
  25. data/dummy/psql/app/controllers/concerns/.keep +0 -0
  26. data/dummy/psql/app/controllers/posts_controller.rb +59 -0
  27. data/dummy/psql/app/helpers/application_helper.rb +2 -0
  28. data/dummy/psql/app/helpers/posts_helper.rb +2 -0
  29. data/dummy/psql/app/models/application_record.rb +3 -0
  30. data/dummy/psql/app/models/concerns/.keep +0 -0
  31. data/dummy/psql/app/models/post.rb +2 -0
  32. data/dummy/psql/app/views/layouts/application.html.erb +15 -0
  33. data/dummy/psql/app/views/posts/_form.html.erb +27 -0
  34. data/dummy/psql/app/views/posts/_post.html.erb +12 -0
  35. data/dummy/psql/app/views/posts/edit.html.erb +10 -0
  36. data/dummy/psql/app/views/posts/index.html.erb +14 -0
  37. data/dummy/psql/app/views/posts/new.html.erb +9 -0
  38. data/dummy/psql/app/views/posts/show.html.erb +10 -0
  39. data/dummy/psql/bin/bundle +109 -0
  40. data/dummy/psql/bin/rails +4 -0
  41. data/dummy/psql/bin/rake +4 -0
  42. data/dummy/psql/bin/setup +33 -0
  43. data/dummy/psql/config/application.rb +43 -0
  44. data/dummy/psql/config/boot.rb +3 -0
  45. data/dummy/psql/config/credentials.yml.enc +1 -0
  46. data/dummy/psql/config/database.yml +87 -0
  47. data/dummy/psql/config/environment.rb +5 -0
  48. data/dummy/psql/config/environments/development.rb +62 -0
  49. data/dummy/psql/config/environments/production.rb +75 -0
  50. data/dummy/psql/config/environments/test.rb +50 -0
  51. data/dummy/psql/config/locales/en.yml +33 -0
  52. data/dummy/psql/config/master.key +1 -0
  53. data/dummy/psql/config/puma.rb +43 -0
  54. data/dummy/psql/config/routes.rb +7 -0
  55. data/dummy/psql/config.ru +6 -0
  56. data/dummy/psql/db/migrate/20230330203226_create_posts.rb +10 -0
  57. data/dummy/psql/db/schema.rb +23 -0
  58. data/dummy/psql/db/seeds.rb +8 -0
  59. data/dummy/psql/log/.keep +0 -0
  60. data/dummy/psql/public/404.html +67 -0
  61. data/dummy/psql/public/422.html +67 -0
  62. data/dummy/psql/public/500.html +66 -0
  63. data/dummy/psql/public/apple-touch-icon-precomposed.png +0 -0
  64. data/dummy/psql/public/apple-touch-icon.png +0 -0
  65. data/dummy/psql/public/favicon.ico +0 -0
  66. data/dummy/psql/public/robots.txt +1 -0
  67. data/dummy/psql/tmp/.keep +0 -0
  68. data/dummy/psql/tmp/pids/.keep +0 -0
  69. data/lib/backy/app_config.rb +11 -0
  70. data/lib/backy/cli.rb +0 -0
  71. data/lib/backy/configuration.rb +66 -0
  72. data/lib/backy/db.rb +29 -0
  73. data/lib/backy/list.rb +18 -0
  74. data/lib/backy/pg_dump.rb +39 -0
  75. data/lib/backy/pg_restore.rb +27 -0
  76. data/lib/backy/railtie.rb +19 -0
  77. data/lib/backy/s3.rb +27 -0
  78. data/lib/backy/s3_list.rb +31 -0
  79. data/lib/backy/s3_load.rb +41 -0
  80. data/lib/backy/s3_save.rb +33 -0
  81. data/lib/backy/version.rb +3 -0
  82. data/lib/backy.rb +30 -0
  83. data/lib/tasks/backy_tasks.rake +84 -0
  84. metadata +291 -0
@@ -0,0 +1,33 @@
1
+ module Backy
2
+ class S3Save
3
+ include S3
4
+
5
+ DEFAULT_EXPIRE_AFTER = 1.month
6
+
7
+ def initialize(file_name:, key: nil, expire_after: nil)
8
+ @file_name = file_name
9
+ @key = key || file_name
10
+ @expires = (expire_after || DEFAULT_EXPIRE_AFTER).from_now
11
+ end
12
+
13
+ def call
14
+ print "Sending #{file_name} to S3 ... "
15
+
16
+ unless File.exist?(file_name)
17
+ puts "error. #{file_name} does not exist"
18
+
19
+ return
20
+ end
21
+
22
+ File.open(file_name, "rb") do |body|
23
+ s3.put_object(key: key, body: body, bucket: bucket, expires: expires)
24
+ end
25
+
26
+ puts "done"
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :file_name, :key, :expires
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Backy
2
+ VERSION = "0.1.3"
3
+ end
data/lib/backy.rb ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/integer/time"
4
+ require "active_support/core_ext/object/blank"
5
+
6
+ require_relative "backy/configuration"
7
+ require_relative "backy/app_config"
8
+ require_relative "backy/db"
9
+ require_relative "backy/list"
10
+ require_relative "backy/pg_dump"
11
+ require_relative "backy/pg_restore"
12
+ require_relative "backy/s3"
13
+ require_relative "backy/s3_list"
14
+ require_relative "backy/s3_load"
15
+ require_relative "backy/s3_save"
16
+ require_relative "backy/version"
17
+
18
+ require_relative "backy/railtie" if defined?(Rails::Railtie)
19
+
20
+ module Backy
21
+ class Error < StandardError; end
22
+
23
+ def self.configure
24
+ yield(configuration)
25
+ end
26
+
27
+ def self.configuration
28
+ @configuration ||= Configuration.new
29
+ end
30
+ end
@@ -0,0 +1,84 @@
1
+ require "aws-sdk-s3"
2
+
3
+ namespace :backy do
4
+ task dump: :environment do
5
+ pg_dump
6
+ end
7
+
8
+ task push: :environment do
9
+ file_name = pg_dump
10
+ save_to_s3(file_name)
11
+ File.delete(file_name) if File.exist?(file_name)
12
+ end
13
+
14
+ task upload: :environment do
15
+ file_name = ENV["DUMP_FILE"]
16
+
17
+ if file_name.nil? || !File.exist?(file_name)
18
+ puts "Plese set DUMP_FILE env variable to the existing local file to save to S3"
19
+
20
+ exit
21
+ end
22
+
23
+ save_to_s3(file_name)
24
+ end
25
+
26
+ task download: :environment do
27
+ file_name = ENV["DUMP_FILE"]
28
+
29
+ if file_name.nil? || File.exist?(file_name)
30
+ puts "Plese set DUMP_FILE env variable to the missing remote file to download"
31
+
32
+ exit
33
+ end
34
+
35
+ load_from_s3_if_missing(file_name)
36
+ end
37
+
38
+ task list: :environment do
39
+ list = Backy::List.new.call
40
+
41
+ list.each do |list_item|
42
+ puts "#{list_item.local? ? "local" : " "} #{list_item.remote? ? "remote" : " "} : #{list_item.dump_file}"
43
+ end
44
+
45
+ if list.any?
46
+ puts
47
+
48
+ puts "To restore run backy:restore setting DUMP_FILE."
49
+ puts "Example:"
50
+ puts " bundle exec rails backy:restore DUMP_FILE=#{list.last.dump_file}"
51
+ end
52
+ end
53
+
54
+ task restore: :environment do
55
+ template_file_name = ENV["DUMP_FILE"]
56
+ file_name = Backy::List.new.call.reverse.find { |list_item| list_item.dump_file.starts_with?(template_file_name) }&.dump_file if template_file_name.present?
57
+
58
+ if file_name.nil?
59
+ puts "Plese set DUMP_FILE env variable to the local/s3 file (or prefix) to restore from."
60
+
61
+ exit
62
+ end
63
+
64
+ pg_restore(load_from_s3_if_missing(file_name))
65
+ end
66
+
67
+ private
68
+
69
+ def pg_dump
70
+ Backy::PgDump.new.call
71
+ end
72
+
73
+ def save_to_s3(file_name)
74
+ Backy::S3Save.new(file_name: file_name).call
75
+ end
76
+
77
+ def load_from_s3_if_missing(file_name)
78
+ Backy::S3Load.new(file_name: file_name).call
79
+ end
80
+
81
+ def pg_restore(file_name)
82
+ Backy::PgRestore.new(file_name: file_name).call
83
+ end
84
+ end
metadata ADDED
@@ -0,0 +1,291 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: backy_rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Alexey Kharchenko
8
+ - Martin Ulleberg
9
+ - Pål André Sundt
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2023-06-16 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '3.0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rubocop
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '1.44'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.44'
43
+ - !ruby/object:Gem::Dependency
44
+ name: standard
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.24'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '1.24'
57
+ - !ruby/object:Gem::Dependency
58
+ name: brakeman
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '5.4'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '5.4'
71
+ - !ruby/object:Gem::Dependency
72
+ name: rubocop-rspec
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '2.18'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: '2.18'
85
+ - !ruby/object:Gem::Dependency
86
+ name: rubocop-performance
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '1.15'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - "~>"
97
+ - !ruby/object:Gem::Version
98
+ version: '1.15'
99
+ - !ruby/object:Gem::Dependency
100
+ name: rubocop-rake
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: 0.6.0
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - "~>"
111
+ - !ruby/object:Gem::Version
112
+ version: 0.6.0
113
+ - !ruby/object:Gem::Dependency
114
+ name: timecop
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: 0.9.6
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - "~>"
125
+ - !ruby/object:Gem::Version
126
+ version: 0.9.6
127
+ - !ruby/object:Gem::Dependency
128
+ name: activerecord
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '4.0'
134
+ type: :runtime
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '4.0'
141
+ - !ruby/object:Gem::Dependency
142
+ name: activesupport
143
+ requirement: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '4.0'
148
+ type: :runtime
149
+ prerelease: false
150
+ version_requirements: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '4.0'
155
+ - !ruby/object:Gem::Dependency
156
+ name: aws-sdk-s3
157
+ requirement: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '1.117'
162
+ type: :runtime
163
+ prerelease: false
164
+ version_requirements: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '1.117'
169
+ description: Backy is a comprehensive database backup solution for Ruby on Rails applications,
170
+ created to help developers manage and safeguard their data with ease. This robust
171
+ gem offers a wide range of features
172
+ email:
173
+ - akharchenko@gmail.com
174
+ - martin.ulleberg@gmail.com
175
+ - pal@rubynor.com
176
+ executables: []
177
+ extensions: []
178
+ extra_rdoc_files: []
179
+ files:
180
+ - ".drone.yml"
181
+ - ".idea/.gitignore"
182
+ - ".rspec"
183
+ - ".rubocop.yml"
184
+ - CHANGELOG.md
185
+ - Gemfile
186
+ - Gemfile.lock
187
+ - README.md
188
+ - Rakefile
189
+ - backy.gemspec
190
+ - bucky.png
191
+ - config/database.example.yml
192
+ - dummy/psql/.gitattributes
193
+ - dummy/psql/.gitignore
194
+ - dummy/psql/.ruby-version
195
+ - dummy/psql/Gemfile
196
+ - dummy/psql/Gemfile.lock
197
+ - dummy/psql/README.md
198
+ - dummy/psql/Rakefile
199
+ - dummy/psql/app/assets/config/manifest.js
200
+ - dummy/psql/app/assets/images/.keep
201
+ - dummy/psql/app/assets/stylesheets/application.css
202
+ - dummy/psql/app/controllers/application_controller.rb
203
+ - dummy/psql/app/controllers/concerns/.keep
204
+ - dummy/psql/app/controllers/posts_controller.rb
205
+ - dummy/psql/app/helpers/application_helper.rb
206
+ - dummy/psql/app/helpers/posts_helper.rb
207
+ - dummy/psql/app/models/application_record.rb
208
+ - dummy/psql/app/models/concerns/.keep
209
+ - dummy/psql/app/models/post.rb
210
+ - dummy/psql/app/views/layouts/application.html.erb
211
+ - dummy/psql/app/views/posts/_form.html.erb
212
+ - dummy/psql/app/views/posts/_post.html.erb
213
+ - dummy/psql/app/views/posts/edit.html.erb
214
+ - dummy/psql/app/views/posts/index.html.erb
215
+ - dummy/psql/app/views/posts/new.html.erb
216
+ - dummy/psql/app/views/posts/show.html.erb
217
+ - dummy/psql/bin/bundle
218
+ - dummy/psql/bin/rails
219
+ - dummy/psql/bin/rake
220
+ - dummy/psql/bin/setup
221
+ - dummy/psql/config.ru
222
+ - dummy/psql/config/application.rb
223
+ - dummy/psql/config/boot.rb
224
+ - dummy/psql/config/credentials.yml.enc
225
+ - dummy/psql/config/database.yml
226
+ - dummy/psql/config/environment.rb
227
+ - dummy/psql/config/environments/development.rb
228
+ - dummy/psql/config/environments/production.rb
229
+ - dummy/psql/config/environments/test.rb
230
+ - dummy/psql/config/locales/en.yml
231
+ - dummy/psql/config/master.key
232
+ - dummy/psql/config/puma.rb
233
+ - dummy/psql/config/routes.rb
234
+ - dummy/psql/db/migrate/20230330203226_create_posts.rb
235
+ - dummy/psql/db/schema.rb
236
+ - dummy/psql/db/seeds.rb
237
+ - dummy/psql/log/.keep
238
+ - dummy/psql/public/404.html
239
+ - dummy/psql/public/422.html
240
+ - dummy/psql/public/500.html
241
+ - dummy/psql/public/apple-touch-icon-precomposed.png
242
+ - dummy/psql/public/apple-touch-icon.png
243
+ - dummy/psql/public/favicon.ico
244
+ - dummy/psql/public/robots.txt
245
+ - dummy/psql/tmp/.keep
246
+ - dummy/psql/tmp/pids/.keep
247
+ - lib/backy.rb
248
+ - lib/backy/app_config.rb
249
+ - lib/backy/cli.rb
250
+ - lib/backy/configuration.rb
251
+ - lib/backy/db.rb
252
+ - lib/backy/list.rb
253
+ - lib/backy/pg_dump.rb
254
+ - lib/backy/pg_restore.rb
255
+ - lib/backy/railtie.rb
256
+ - lib/backy/s3.rb
257
+ - lib/backy/s3_list.rb
258
+ - lib/backy/s3_load.rb
259
+ - lib/backy/s3_save.rb
260
+ - lib/backy/version.rb
261
+ - lib/tasks/backy_tasks.rake
262
+ homepage: https://rubynor.com
263
+ licenses: []
264
+ metadata:
265
+ homepage_uri: https://rubynor.com
266
+ source_code_uri: https://github.com/rubynor/backy
267
+ changelog_uri: https://github.com/rubynor/backy/blob/main/CHANGELOG.md
268
+ post_install_message:
269
+ rdoc_options: []
270
+ require_paths:
271
+ - lib
272
+ required_ruby_version: !ruby/object:Gem::Requirement
273
+ requirements:
274
+ - - ">="
275
+ - !ruby/object:Gem::Version
276
+ version: 2.2.0
277
+ required_rubygems_version: !ruby/object:Gem::Requirement
278
+ requirements:
279
+ - - ">="
280
+ - !ruby/object:Gem::Version
281
+ version: '0'
282
+ requirements: []
283
+ rubygems_version: 3.4.1
284
+ signing_key:
285
+ specification_version: 4
286
+ summary: Backy is a powerful and user-friendly database backup gem designed specifically
287
+ for Ruby on Rails applications. It streamlines the backup process, ensuring your
288
+ data is safe, secure, and easily retrievable. With its versatile features and easy
289
+ integration, Backy is the go-to solution for Rails developers looking to protect
290
+ their valuable information.
291
+ test_files: []