sg_tiny_backup 1.0.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.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/main.yml +51 -0
  3. data/.gitignore +14 -0
  4. data/.octocov.yml +15 -0
  5. data/.rspec +3 -0
  6. data/.rubocop.yml +70 -0
  7. data/.ruby-version +1 -0
  8. data/.simplecov +14 -0
  9. data/CHANGELOG.md +73 -0
  10. data/Gemfile +23 -0
  11. data/Gemfile.lock +175 -0
  12. data/LICENSE.txt +21 -0
  13. data/README.md +111 -0
  14. data/Rakefile +12 -0
  15. data/bin/console +15 -0
  16. data/bin/setup +8 -0
  17. data/config/database.ci.yml +15 -0
  18. data/lib/sg_tiny_backup/commands/aws_cli.rb +32 -0
  19. data/lib/sg_tiny_backup/commands/base.rb +23 -0
  20. data/lib/sg_tiny_backup/commands/gzip.rb +20 -0
  21. data/lib/sg_tiny_backup/commands/mysql_dump.rb +38 -0
  22. data/lib/sg_tiny_backup/commands/openssl.rb +40 -0
  23. data/lib/sg_tiny_backup/commands/pg_dump.rb +38 -0
  24. data/lib/sg_tiny_backup/commands/tar.rb +68 -0
  25. data/lib/sg_tiny_backup/commands.rb +8 -0
  26. data/lib/sg_tiny_backup/config.rb +71 -0
  27. data/lib/sg_tiny_backup/error.rb +25 -0
  28. data/lib/sg_tiny_backup/pipeline.rb +62 -0
  29. data/lib/sg_tiny_backup/pipeline_builders/base.rb +37 -0
  30. data/lib/sg_tiny_backup/pipeline_builders/db.rb +70 -0
  31. data/lib/sg_tiny_backup/pipeline_builders/log.rb +36 -0
  32. data/lib/sg_tiny_backup/pipeline_builders/s3.rb +26 -0
  33. data/lib/sg_tiny_backup/railtie.rb +9 -0
  34. data/lib/sg_tiny_backup/runner.rb +77 -0
  35. data/lib/sg_tiny_backup/spawner.rb +113 -0
  36. data/lib/sg_tiny_backup/templates/sg_tiny_backup.yml +43 -0
  37. data/lib/sg_tiny_backup/utils.rb +34 -0
  38. data/lib/sg_tiny_backup/version.rb +5 -0
  39. data/lib/sg_tiny_backup.rb +21 -0
  40. data/lib/tasks/sg_tiny_backup.rake +78 -0
  41. data/sg_tiny_backup.gemspec +38 -0
  42. metadata +87 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7657fb65d7238a037c1ed6ad75d954e347e2ffde52a3acb9db151338419c5f50
4
+ data.tar.gz: fe271ecb8be55c0ccf480bc55b5042149255ece63fba6129e3965fc274acbdae
5
+ SHA512:
6
+ metadata.gz: 63df85d8b745ffd2d4a35c4671deba8a3a52b63dbd308d45636aef10dc094132f916faa55b7ec630dca4cd336876ed284af0151644cc7ece6b79b40de7fdc47c
7
+ data.tar.gz: e16d559b3902e605ed720dafe0955d6cbc3f7f54e1e9e110da6d7384e22f85427aab775a2875dc037885757b941bc57a71fcbd70904b1815a7663e64a4a77690
@@ -0,0 +1,51 @@
1
+ name: Ruby
2
+
3
+ on: [pull_request]
4
+
5
+ concurrency:
6
+ group: ${{ github.workflow }}-${{ github.ref }}
7
+ cancel-in-progress: true
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+
13
+ strategy:
14
+ matrix:
15
+ ruby-version: ["4.0", "3.4", "3.3", "3.2"]
16
+
17
+ services:
18
+ postgres:
19
+ image: postgres:13
20
+ ports: ["5432:5432"]
21
+ options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
22
+ env:
23
+ POSTGRES_USER: postgres
24
+ POSTGRES_PASSWORD: postgres
25
+ mysql:
26
+ image: mysql:8
27
+ ports: ["3306:3306"]
28
+ options: --health-cmd "mysqladmin ping -h 127.0.0.1" --health-interval 10s --health-timeout 5s --health-retries 5
29
+ env:
30
+ MYSQL_ROOT_PASSWORD: password
31
+
32
+ steps:
33
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
34
+ - name: Set up Ruby ${{ matrix.ruby-version }}
35
+ uses: ruby/setup-ruby@09a7688d3b55cf0e976497ff046b70949eeaccfd # v1.288.0
36
+ with:
37
+ ruby-version: ${{ matrix.ruby-version }}
38
+ bundler-cache: true
39
+ - name: Copy database config
40
+ run: cp config/database.ci.yml config/database.yml
41
+ - name: rspec
42
+ run: bundle exec rspec
43
+ - name: rubocop
44
+ run: bundle exec rubocop
45
+ - uses: k1LoW/octocov-action@73d561f65d59e66899ed5c87e4621a913b5d5c20 # v1.5.0
46
+ - name: Archive coverage artifacts
47
+ uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
48
+ with:
49
+ name: coverage-ruby-${{ matrix.ruby-version }}
50
+ path: coverage
51
+ if: always()
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /config/database.yml
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+
14
+ .vscode
data/.octocov.yml ADDED
@@ -0,0 +1,15 @@
1
+ # generated by octocov init
2
+ coverage:
3
+ if: true
4
+ acceptable: 90%
5
+ testExecutionTime:
6
+ if: true
7
+ diff:
8
+ datastores:
9
+ - artifact://${GITHUB_REPOSITORY}
10
+ comment:
11
+ if: is_pull_request
12
+ report:
13
+ if: is_default_branch
14
+ datastores:
15
+ - artifact://${GITHUB_REPOSITORY}
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,70 @@
1
+ require:
2
+ - rubocop-rspec
3
+ - rubocop-rake
4
+
5
+ AllCops:
6
+ NewCops: enable
7
+ TargetRubyVersion: 3.2
8
+
9
+ Layout/LineLength:
10
+ Max: 150
11
+
12
+ Layout/ArrayAlignment:
13
+ Enabled: true
14
+ EnforcedStyle: with_fixed_indentation
15
+
16
+ Layout/FirstArrayElementIndentation:
17
+ Enabled: true
18
+ EnforcedStyle: consistent
19
+
20
+ Style/StringLiterals:
21
+ Enabled: true
22
+ EnforcedStyle: double_quotes
23
+
24
+ Style/StringLiteralsInInterpolation:
25
+ Enabled: true
26
+ EnforcedStyle: double_quotes
27
+
28
+ Style/TrailingCommaInHashLiteral:
29
+ Enabled: true
30
+ EnforcedStyleForMultiline: consistent_comma
31
+
32
+ Style/TrailingCommaInArrayLiteral:
33
+ Enabled: true
34
+ EnforcedStyleForMultiline: consistent_comma
35
+
36
+ Style/NumericPredicate:
37
+ Enabled: false
38
+
39
+ Style/Documentation:
40
+ Enabled: false
41
+
42
+ Style/GlobalStdStream:
43
+ Enabled: false
44
+
45
+ Naming/MethodParameterName:
46
+ Enabled: true
47
+ MinNameLength: 2
48
+
49
+ Metrics/MethodLength:
50
+ Enabled: true
51
+ Max: 100
52
+
53
+ Metrics/BlockLength:
54
+ Enabled: true
55
+ Max: 100
56
+
57
+ RSpec/DescribeClass:
58
+ Enabled: false
59
+
60
+ RSpec/DescribedClass:
61
+ Enabled: false
62
+
63
+ RSpec/ExampleLength:
64
+ Max: 100
65
+
66
+ RSpec/MultipleExpectations:
67
+ Enabled: false
68
+
69
+ RSpec/ReceiveMessages:
70
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.9
data/.simplecov ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "simplecov-lcov"
4
+
5
+ SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
7
+ SimpleCov::Formatter::LcovFormatter,
8
+ SimpleCov::Formatter::HTMLFormatter,
9
+ ])
10
+
11
+ SimpleCov.start do
12
+ add_filter "/spec/"
13
+ add_filter "/vendor/bundle/"
14
+ end
data/CHANGELOG.md ADDED
@@ -0,0 +1,73 @@
1
+ ## [1.0.0] - 2026-03-03
2
+
3
+ ### Breaking changes
4
+
5
+ - Drop support for Ruby 3.1 and below
6
+
7
+ ### Features
8
+
9
+ - Add gzip compression level option
10
+
11
+ ### Fixes
12
+
13
+ - Fix bug in Gzip command where level option was not appended correctly
14
+
15
+ ## [0.10.0] - 2024-03-18
16
+
17
+ - Fix loading YAML with ERB
18
+
19
+ ## [0.9.0] - 2023-06-27
20
+
21
+ - Read config/database.yml values as ERB.
22
+
23
+ ## [0.8.0] - 2023-04-13
24
+
25
+ ### Breaking changes
26
+
27
+ - If log files in `log > files` field are missing, the gem raise BackupFailed.
28
+ - If log files are optional, use `optional_files` as YAML key instead of `files`.
29
+
30
+ ## [0.7.0] - 2022-12-16
31
+
32
+ - MySQL backup support
33
+
34
+ ## [0.6.0] - 2022-10-27
35
+
36
+ - If log files are missing, invoke tar command with only existing files and raise BackupWarning after the backup finished.
37
+
38
+ ## [0.5.0] - 2022-09-01
39
+
40
+ ### Fixes
41
+
42
+ - The backup rake task fails if GNU tar exits with code 1
43
+
44
+ ### Breaking changes
45
+
46
+ - `SgTinyBackup.raise_on_error` is true by default
47
+
48
+ ## [0.4.0] - 2022-08-27
49
+
50
+ ### Features
51
+
52
+ - Rake tasks use BACKUP_TARGET environment variable
53
+
54
+ ## [0.3.0] - 2022-08-27
55
+
56
+ ### Breaking changes
57
+
58
+ - Change S3 path
59
+ - Log backup filename includes hostname
60
+
61
+ ## [0.2.0] - 2022-08-27
62
+
63
+ ### Features
64
+
65
+ - Log backup
66
+
67
+ ### Breaking changes
68
+
69
+ - S3 configuration changed to support log backup
70
+
71
+ ## [0.1.0] - 2022-08-18
72
+
73
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in sg_tiny_backup.gemspec
6
+ gemspec
7
+
8
+ gem "rake"
9
+
10
+ gem "rspec"
11
+
12
+ gem "rubocop"
13
+ gem "rubocop-rake"
14
+ gem "rubocop-rspec"
15
+
16
+ gem "simplecov"
17
+ gem "simplecov-lcov"
18
+
19
+ gem "debug"
20
+
21
+ # ruby 4.0 bundled gems
22
+ gem "logger"
23
+ gem "ostruct"
data/Gemfile.lock ADDED
@@ -0,0 +1,175 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sg_tiny_backup (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.8.9)
10
+ public_suffix (>= 2.0.2, < 8.0)
11
+ ast (2.4.3)
12
+ bigdecimal (4.0.1)
13
+ date (3.5.1)
14
+ debug (1.11.1)
15
+ irb (~> 1.10)
16
+ reline (>= 0.3.8)
17
+ diff-lcs (1.6.2)
18
+ docile (1.4.1)
19
+ erb (6.0.2)
20
+ io-console (0.8.2)
21
+ irb (1.17.0)
22
+ pp (>= 0.6.0)
23
+ prism (>= 1.3.0)
24
+ rdoc (>= 4.0.0)
25
+ reline (>= 0.4.2)
26
+ json (2.18.1)
27
+ json-schema (6.1.0)
28
+ addressable (~> 2.8)
29
+ bigdecimal (>= 3.1, < 5)
30
+ language_server-protocol (3.17.0.5)
31
+ lint_roller (1.1.0)
32
+ logger (1.7.0)
33
+ mcp (0.8.0)
34
+ json-schema (>= 4.1)
35
+ ostruct (0.6.3)
36
+ parallel (1.27.0)
37
+ parser (3.3.10.2)
38
+ ast (~> 2.4.1)
39
+ racc
40
+ pp (0.6.3)
41
+ prettyprint
42
+ prettyprint (0.2.0)
43
+ prism (1.9.0)
44
+ psych (5.3.1)
45
+ date
46
+ stringio
47
+ public_suffix (7.0.2)
48
+ racc (1.8.1)
49
+ rainbow (3.1.1)
50
+ rake (13.3.1)
51
+ rdoc (7.2.0)
52
+ erb
53
+ psych (>= 4.0.0)
54
+ tsort
55
+ regexp_parser (2.11.3)
56
+ reline (0.6.3)
57
+ io-console (~> 0.5)
58
+ rspec (3.13.2)
59
+ rspec-core (~> 3.13.0)
60
+ rspec-expectations (~> 3.13.0)
61
+ rspec-mocks (~> 3.13.0)
62
+ rspec-core (3.13.6)
63
+ rspec-support (~> 3.13.0)
64
+ rspec-expectations (3.13.5)
65
+ diff-lcs (>= 1.2.0, < 2.0)
66
+ rspec-support (~> 3.13.0)
67
+ rspec-mocks (3.13.8)
68
+ diff-lcs (>= 1.2.0, < 2.0)
69
+ rspec-support (~> 3.13.0)
70
+ rspec-support (3.13.7)
71
+ rubocop (1.85.0)
72
+ json (~> 2.3)
73
+ language_server-protocol (~> 3.17.0.2)
74
+ lint_roller (~> 1.1.0)
75
+ mcp (~> 0.6)
76
+ parallel (~> 1.10)
77
+ parser (>= 3.3.0.2)
78
+ rainbow (>= 2.2.2, < 4.0)
79
+ regexp_parser (>= 2.9.3, < 3.0)
80
+ rubocop-ast (>= 1.49.0, < 2.0)
81
+ ruby-progressbar (~> 1.7)
82
+ unicode-display_width (>= 2.4.0, < 4.0)
83
+ rubocop-ast (1.49.0)
84
+ parser (>= 3.3.7.2)
85
+ prism (~> 1.7)
86
+ rubocop-rake (0.7.1)
87
+ lint_roller (~> 1.1)
88
+ rubocop (>= 1.72.1)
89
+ rubocop-rspec (3.9.0)
90
+ lint_roller (~> 1.1)
91
+ rubocop (~> 1.81)
92
+ ruby-progressbar (1.13.0)
93
+ simplecov (0.22.0)
94
+ docile (~> 1.1)
95
+ simplecov-html (~> 0.11)
96
+ simplecov_json_formatter (~> 0.1)
97
+ simplecov-html (0.13.2)
98
+ simplecov-lcov (0.9.0)
99
+ simplecov_json_formatter (0.1.4)
100
+ stringio (3.2.0)
101
+ tsort (0.2.0)
102
+ unicode-display_width (3.2.0)
103
+ unicode-emoji (~> 4.1)
104
+ unicode-emoji (4.2.0)
105
+
106
+ PLATFORMS
107
+ ruby
108
+ x86_64-linux
109
+
110
+ DEPENDENCIES
111
+ debug
112
+ logger
113
+ ostruct
114
+ rake
115
+ rspec
116
+ rubocop
117
+ rubocop-rake
118
+ rubocop-rspec
119
+ sg_tiny_backup!
120
+ simplecov
121
+ simplecov-lcov
122
+
123
+ CHECKSUMS
124
+ addressable (2.8.9) sha256=cc154fcbe689711808a43601dee7b980238ce54368d23e127421753e46895485
125
+ ast (2.4.3) sha256=954615157c1d6a382bc27d690d973195e79db7f55e9765ac7c481c60bdb4d383
126
+ bigdecimal (4.0.1) sha256=8b07d3d065a9f921c80ceaea7c9d4ae596697295b584c296fe599dd0ad01c4a7
127
+ date (3.5.1) sha256=750d06384d7b9c15d562c76291407d89e368dda4d4fff957eb94962d325a0dc0
128
+ debug (1.11.1) sha256=2e0b0ac6119f2207a6f8ac7d4a73ca8eb4e440f64da0a3136c30343146e952b6
129
+ diff-lcs (1.6.2) sha256=9ae0d2cba7d4df3075fe8cd8602a8604993efc0dfa934cff568969efb1909962
130
+ docile (1.4.1) sha256=96159be799bfa73cdb721b840e9802126e4e03dfc26863db73647204c727f21e
131
+ erb (6.0.2) sha256=9fe6264d44f79422c87490a1558479bd0e7dad4dd0e317656e67ea3077b5242b
132
+ io-console (0.8.2) sha256=d6e3ae7a7cc7574f4b8893b4fca2162e57a825b223a177b7afa236c5ef9814cc
133
+ irb (1.17.0) sha256=168c4ddb93d8a361a045c41d92b2952c7a118fa73f23fe14e55609eb7a863aae
134
+ json (2.18.1) sha256=fe112755501b8d0466b5ada6cf50c8c3f41e897fa128ac5d263ec09eedc9f986
135
+ json-schema (6.1.0) sha256=6bf70a2cfb6dfd5a06da28093fa8190f324c88eabd36a7f47097f227321dc702
136
+ language_server-protocol (3.17.0.5) sha256=fd1e39a51a28bf3eec959379985a72e296e9f9acfce46f6a79d31ca8760803cc
137
+ lint_roller (1.1.0) sha256=2c0c845b632a7d172cb849cc90c1bce937a28c5c8ccccb50dfd46a485003cc87
138
+ logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203
139
+ mcp (0.8.0) sha256=ae8bd146bb8e168852866fd26f805f52744f6326afb3211e073f78a95e0c34fb
140
+ ostruct (0.6.3) sha256=95a2ed4a4bd1d190784e666b47b2d3f078e4a9efda2fccf18f84ddc6538ed912
141
+ parallel (1.27.0) sha256=4ac151e1806b755fb4e2dc2332cbf0e54f2e24ba821ff2d3dcf86bf6dc4ae130
142
+ parser (3.3.10.2) sha256=6f60c84aa4bdcedb6d1a2434b738fe8a8136807b6adc8f7f53b97da9bc4e9357
143
+ pp (0.6.3) sha256=2951d514450b93ccfeb1df7d021cae0da16e0a7f95ee1e2273719669d0ab9df6
144
+ prettyprint (0.2.0) sha256=2bc9e15581a94742064a3cc8b0fb9d45aae3d03a1baa6ef80922627a0766f193
145
+ prism (1.9.0) sha256=7b530c6a9f92c24300014919c9dcbc055bf4cdf51ec30aed099b06cd6674ef85
146
+ psych (5.3.1) sha256=eb7a57cef10c9d70173ff74e739d843ac3b2c019a003de48447b2963d81b1974
147
+ public_suffix (7.0.2) sha256=9114090c8e4e7135c1fd0e7acfea33afaab38101884320c65aaa0ffb8e26a857
148
+ racc (1.8.1) sha256=4a7f6929691dbec8b5209a0b373bc2614882b55fc5d2e447a21aaa691303d62f
149
+ rainbow (3.1.1) sha256=039491aa3a89f42efa1d6dec2fc4e62ede96eb6acd95e52f1ad581182b79bc6a
150
+ rake (13.3.1) sha256=8c9e89d09f66a26a01264e7e3480ec0607f0c497a861ef16063604b1b08eb19c
151
+ rdoc (7.2.0) sha256=8650f76cd4009c3b54955eb5d7e3a075c60a57276766ebf36f9085e8c9f23192
152
+ regexp_parser (2.11.3) sha256=ca13f381a173b7a93450e53459075c9b76a10433caadcb2f1180f2c741fc55a4
153
+ reline (0.6.3) sha256=1198b04973565b36ec0f11542ab3f5cfeeec34823f4e54cebde90968092b1835
154
+ rspec (3.13.2) sha256=206284a08ad798e61f86d7ca3e376718d52c0bc944626b2349266f239f820587
155
+ rspec-core (3.13.6) sha256=a8823c6411667b60a8bca135364351dda34cd55e44ff94c4be4633b37d828b2d
156
+ rspec-expectations (3.13.5) sha256=33a4d3a1d95060aea4c94e9f237030a8f9eae5615e9bd85718fe3a09e4b58836
157
+ rspec-mocks (3.13.8) sha256=086ad3d3d17533f4237643de0b5c42f04b66348c28bf6b9c2d3f4a3b01af1d47
158
+ rspec-support (3.13.7) sha256=0640e5570872aafefd79867901deeeeb40b0c9875a36b983d85f54fb7381c47c
159
+ rubocop (1.85.0) sha256=317407feb681a07d54f64d2f9e1d6b6af1ce7678e51cd658e3ad8bd66da48c01
160
+ rubocop-ast (1.49.0) sha256=49c3676d3123a0923d333e20c6c2dbaaae2d2287b475273fddee0c61da9f71fd
161
+ rubocop-rake (0.7.1) sha256=3797f2b6810c3e9df7376c26d5f44f3475eda59eb1adc38e6f62ecf027cbae4d
162
+ rubocop-rspec (3.9.0) sha256=8fa70a3619408237d789aeecfb9beef40576acc855173e60939d63332fdb55e2
163
+ ruby-progressbar (1.13.0) sha256=80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33
164
+ sg_tiny_backup (1.0.0)
165
+ simplecov (0.22.0) sha256=fe2622c7834ff23b98066bb0a854284b2729a569ac659f82621fc22ef36213a5
166
+ simplecov-html (0.13.2) sha256=bd0b8e54e7c2d7685927e8d6286466359b6f16b18cb0df47b508e8d73c777246
167
+ simplecov-lcov (0.9.0) sha256=7a77a31e200a595ed4b0249493056efd0c920601f53d2ef135ca34ee796346cd
168
+ simplecov_json_formatter (0.1.4) sha256=529418fbe8de1713ac2b2d612aa3daa56d316975d307244399fa4838c601b428
169
+ stringio (3.2.0) sha256=c37cb2e58b4ffbd33fe5cd948c05934af997b36e0b6ca6fdf43afa234cf222e1
170
+ tsort (0.2.0) sha256=9650a793f6859a43b6641671278f79cfead60ac714148aabe4e3f0060480089f
171
+ unicode-display_width (3.2.0) sha256=0cdd96b5681a5949cdbc2c55e7b420facae74c4aaf9a9815eee1087cb1853c42
172
+ unicode-emoji (4.2.0) sha256=519e69150f75652e40bf736106cfbc8f0f73aa3fb6a65afe62fefa7f80b0f80f
173
+
174
+ BUNDLED WITH
175
+ 4.0.7
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Shunichi Ikegami
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,111 @@
1
+ # SgTinyBackup
2
+
3
+ Simply backup PostgreSQL/MySQL database and logs to S3.
4
+
5
+ ## Dependencies
6
+
7
+ This gem needs the following softwares.
8
+
9
+ - [pg_dump](https://www.postgresql.org/docs/current/app-pgdump.html)
10
+ - [mysqldump](https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html)
11
+ - [OpenSSL](https://www.openssl.org/)
12
+ - [AWS CLI](https://aws.amazon.com/cli/)
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'sg_tiny_backup', github: 'SonicGarden/sg_tiny_backup'
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ### Generate your config file to `config/sg_tiny_backup.yml`
25
+
26
+ You should modify it according to the comments in it.
27
+
28
+ ```
29
+ bundle exec rake sg_tiny_backup:generate
30
+ ```
31
+
32
+ ### Backup your database to S3
33
+
34
+ ```
35
+ # backup database
36
+ bundle exec rake sg_tiny_backup:backup
37
+
38
+ # backup logs
39
+ bundle exec rake sg_tiny_backup:backup BACKUP_TARGET=log
40
+ ```
41
+
42
+ ### Backup your database to current directory
43
+
44
+ ```
45
+ # backup database
46
+ bundle exec rake sg_tiny_backup:backup_local
47
+
48
+ # backup logs
49
+ bundle exec rake sg_tiny_backup:backup_local BACKUP_TARGET=log
50
+ ```
51
+
52
+ ### Show backup command
53
+
54
+ ```
55
+ # show database backup command
56
+ bundle exec rake sg_tiny_backup:command
57
+
58
+ # show log backup command
59
+ bundle exec rake sg_tiny_backup:command BACKUP_TARGET=log
60
+ ```
61
+
62
+ ### Show decryption command example
63
+
64
+ ```
65
+ bundle exec rake sg_tiny_backup:decryption_command
66
+ ```
67
+
68
+ ## Setting logger
69
+
70
+ Logs are outputted to standard output by default.
71
+
72
+ You can change the logger if you want.
73
+
74
+ ```ruby
75
+ SgTinyBackup.logger = Rails.logger
76
+ ```
77
+
78
+ ## Error reporting
79
+
80
+ If `SgTinyBackup.raise_on_error` is true, the backup task raises an error when the backup command fails.
81
+ So your bug tracking service (like Bugsnag, Sentry, ...) can catch the error.
82
+
83
+ ```ruby
84
+ SgTinyBackup.raise_on_error = true # true by default
85
+ ```
86
+
87
+ ## How it works
88
+
89
+ This gem simply generates a command line string like the following and runs it.
90
+ The credentials are passed to each command by environment variables.
91
+
92
+ ```
93
+ pg_dump --username={USER} --host={HOST} --port={PORT} {DATABASENAME} | \
94
+ gzip | \
95
+ openssl enc -aes-256-cbc -pbkdf2 -iter 10000 -pass env:SG_TINY_BACKUP_ENCRYPTION_KEY | \
96
+ aws s3 cp - s3://{BUCKET}/{PREFIX}{TIMESTAMP}.sql.gz.enc
97
+ ```
98
+
99
+ ## Development
100
+
101
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
102
+
103
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
104
+
105
+ ## Contributing
106
+
107
+ Bug reports and pull requests are welcome on GitHub at https://github.com/SonicGarden/sg_tiny_backup.
108
+
109
+ ## License
110
+
111
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "sg_tiny_backup"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,15 @@
1
+ test:
2
+ adapter: postgresql
3
+ host: localhost
4
+ port: 5432
5
+ username: postgres
6
+ password: postgres
7
+ database: sg_tiny_backup_test
8
+
9
+ test_mysql:
10
+ adapter: mysql2
11
+ host: 127.0.0.1
12
+ port: 3306
13
+ username: root
14
+ password: password
15
+ database: sg_tiny_backup_test
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base"
4
+
5
+ module SgTinyBackup
6
+ module Commands
7
+ class AwsCli < Base
8
+ def initialize(destination_url:, access_key_id:, secret_access_key:, expected_size: nil)
9
+ super()
10
+ @destination_url = destination_url
11
+ @access_key_id = access_key_id
12
+ @secret_access_key = secret_access_key
13
+ @expected_size = expected_size
14
+ end
15
+
16
+ def command
17
+ parts = []
18
+ parts << "aws s3 cp"
19
+ parts << "--expected-size #{@expected_size}" if @expected_size
20
+ parts << "- #{@destination_url}"
21
+ parts.join(" ")
22
+ end
23
+
24
+ def env
25
+ {
26
+ "AWS_ACCESS_KEY_ID" => @access_key_id,
27
+ "AWS_SECRET_ACCESS_KEY" => @secret_access_key,
28
+ }
29
+ end
30
+ end
31
+ end
32
+ end