archivault 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
+ SHA256:
3
+ metadata.gz: 18e7063c221d22627d0355b857c7bd767d14cd2312f2c04391c506cba4ba1689
4
+ data.tar.gz: 2b5649d48fc0eb996bc8377f7670ad1d576cfe18609363079653472f92bea66c
5
+ SHA512:
6
+ metadata.gz: 2de400dc93463d3dd8247eaecdb9a323c59001106e1ad41d145dba5b68d50f03ec8ab2bde6fb7b98b128280a2dee21439bb4340d5a068810f654b91f586b488a
7
+ data.tar.gz: 9a41e8bec7f152ba8ee845e5387dfabcda6f7055ba770c012d1143da1ac81454039d20448b5b74e77527859100f51a21d0582f3af685bbe6187fcd193789fac2
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2026-04-08
4
+
5
+ - Initial release
@@ -0,0 +1,10 @@
1
+ # Code of Conduct
2
+
3
+ "archivault" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
4
+
5
+ * Participants will be tolerant of opposing views.
6
+ * Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
7
+ * When interpreting the words and actions of others, participants should always assume good intentions.
8
+ * Behaviour which can be reasonably considered harassment will not be tolerated.
9
+
10
+ If you have any concerns about behaviour within this project, please contact us at ["piotr@macuk.pl"](mailto:"piotr@macuk.pl").
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Piotr Macuk
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,112 @@
1
+ # Archivault
2
+
3
+ ArchiVault is a Ruby gem for Rails applications that backs up files, logs, and databases
4
+ using paths and credentials provided by the app. It compresses and encrypts the data,
5
+ then uploads it securely to AWS S3.
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ ```bash
12
+ bundle add archivault
13
+ ```
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ ```bash
18
+ gem install archivault
19
+ ```
20
+
21
+ ## Ruby usage
22
+
23
+ ### SQLite database backup
24
+
25
+ ```ruby
26
+ database_path = "/home/user/app/storage/production.sqlite3"
27
+ gpg_passphrase = "password"
28
+ s3_setup = {
29
+ region: "region",
30
+ access_key_id: "access_key_id",
31
+ secret_access_key: "secret_access_key",
32
+ bucket: "bucket"
33
+ }
34
+ ping_url = "https://example.com/ping" # optional parameter
35
+
36
+ Archivault::SqliteBackup.new(database_path:, gpg_passphrase:, s3_setup:, ping_url:).call
37
+ ```
38
+
39
+ ### Logs backup
40
+
41
+ ```ruby
42
+ log_path_or_paths = %w[
43
+ /home/user/app/log/production.log.1
44
+ /home/user/app/log/nginx_access.log.1
45
+ ]
46
+ gpg_passphrase = "password"
47
+ s3_setup = {
48
+ region: "region",
49
+ access_key_id: "access_key_id",
50
+ secret_access_key: "secret_access_key",
51
+ bucket: "bucket"
52
+ }
53
+ ping_url = "https://example.com/ping" # optional parameter
54
+
55
+ Archivault::LogsBackup.new(log_path_or_paths:, gpg_passphrase:, s3_setup:, ping_url:).call
56
+ ```
57
+
58
+ ## Rais usage
59
+
60
+ ### SQLite database backup
61
+
62
+ ```ruby
63
+ # in config/credentials.yml.enc
64
+ # archivault:
65
+ # gpg_passphrase: password
66
+ # s3_setup:
67
+ # region: region
68
+ # access_key_id: access_key_id
69
+ # secret_access_key: secret_access_key
70
+ # bucket: bucket
71
+ params = {
72
+ database_path: Rails.root.join("storage/production.sqlite3"),
73
+ ping_url: "https://example.com/ping" # optional parameter
74
+ }.merge(Rails.application.credentials.archivault)
75
+ Archivault::SqliteBackup.new(**params).call
76
+ ```
77
+
78
+ ### Logs backup
79
+
80
+ ```ruby
81
+ # in config/credentials.yml.enc
82
+ # archivault:
83
+ # gpg_passphrase: password
84
+ # s3_setup:
85
+ # region: region
86
+ # access_key_id: access_key_id
87
+ # secret_access_key: secret_access_key
88
+ # bucket: bucket
89
+ params = {
90
+ log_path_or_paths: Rails.root.join("log", "production.log.1"),
91
+ ping_url: "https://example.com/ping" # optional parameter
92
+ }.merge(Rails.application.credentials.archivault)
93
+ Archivault::LogsBackup.new(**params).call
94
+ ```
95
+
96
+ ## Development
97
+
98
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
99
+
100
+ 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).
101
+
102
+ ## Contributing
103
+
104
+ Bug reports and pull requests are welcome on GitHub at https://github.com/macuk/archivault. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/macuk/archivault/blob/main/CODE_OF_CONDUCT.md).
105
+
106
+ ## License
107
+
108
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
109
+
110
+ ## Code of Conduct
111
+
112
+ Everyone interacting in the Archivault project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/macuk/archivault/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[test rubocop]
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+
5
+ module Archivault
6
+ class Clean
7
+ def initialize(path_or_paths)
8
+ @paths = Array(path_or_paths)
9
+ raise ArgumentError, "path_or_paths is required" if @paths.empty?
10
+ end
11
+
12
+ def call
13
+ @paths.each do |path|
14
+ raise ArgumentError, "path is required" if path.nil? || path.to_s.empty?
15
+
16
+ FileUtils.rm_f(path.to_s)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "English"
4
+
5
+ module Archivault
6
+ class Execute
7
+ def call(command, *)
8
+ status = system(command, *)
9
+ raise ExecuteError, "#{command} could not be executed" if status.nil?
10
+ raise ExecuteError, "#{command} failed with exit code #{$CHILD_STATUS&.exitstatus}" unless status
11
+
12
+ status
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Archivault
4
+ class Gpg
5
+ def initialize(file_path)
6
+ raise ArgumentError, "file_path is required" if file_path.nil? || file_path.to_s.empty?
7
+
8
+ @file_path = file_path.to_s
9
+ end
10
+
11
+ def call(passphrase)
12
+ raise ArgumentError, "passphrase is required" if passphrase.to_s.strip.empty?
13
+
14
+ Execute.new.call(
15
+ "gpg",
16
+ "--batch",
17
+ "--yes",
18
+ "--symmetric",
19
+ "--cipher-algo", "AES256",
20
+ "--passphrase", passphrase,
21
+ @file_path
22
+ )
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Archivault
4
+ class LogsBackup
5
+ # Parameters
6
+ # - log_path_or_paths: Path or array of paths to the log files to back up
7
+ # - gpg_passphrase: GPG passphrase to encrypt the backup file
8
+ # - s3_setup: Hash of S3 setup options:
9
+ # - region: AWS region
10
+ # - access_key_id: AWS access key ID
11
+ # - secret_access_key: AWS secret access key
12
+ # - bucket: S3 bucket name
13
+ def initialize(log_path_or_paths:, gpg_passphrase:, s3_setup:, ping_url: nil)
14
+ @log_path_or_paths = log_path_or_paths
15
+ @gpg_passphrase = gpg_passphrase.to_s
16
+ @s3_setup = s3_setup
17
+ @ping_url = ping_url
18
+
19
+ @timestamp = Timestamp.new.timestamp
20
+ @tmp_path = Tmp.new.path
21
+ @tar_path = "#{@tmp_path}/logs-#{@timestamp}.tgz"
22
+ @gpg_path = "#{@tar_path}.gpg"
23
+ end
24
+
25
+ def call
26
+ Tar.new(tar_path: @tar_path, path_or_paths: @log_path_or_paths).call
27
+ Gpg.new(@tar_path).call(@gpg_passphrase)
28
+ S3.new(@gpg_path).call(**@s3_setup)
29
+ Ping.new(@ping_url).call if @ping_url
30
+ ensure
31
+ Clean.new([@tar_path, @gpg_path]).call
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Archivault
4
+ class Ping
5
+ def initialize(ping_url)
6
+ raise ArgumentError, "ping_url is required" if ping_url.nil? || ping_url.to_s.empty?
7
+
8
+ @ping_url = ping_url.to_s
9
+ end
10
+
11
+ def call
12
+ Net::HTTP.get_response(URI(@ping_url))
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "aws-sdk-s3"
4
+
5
+ module Archivault
6
+ class S3
7
+ def initialize(file_path)
8
+ raise ArgumentError, "file_path is required" if file_path.nil? || file_path.to_s.empty?
9
+
10
+ @file_path = file_path.to_s
11
+ end
12
+
13
+ def call(region:, access_key_id:, secret_access_key:, bucket:)
14
+ validate_call_arguments!(region:, access_key_id:, secret_access_key:, bucket:)
15
+
16
+ basename = File.basename(@file_path)
17
+ bucket_path = basename.sub(/^(.+)-(\d{4})-(\d{2}).*/, '\1/\2/\3/')
18
+ key = bucket_path + basename
19
+
20
+ s3_client = Aws::S3::Client.new(region:, access_key_id:, secret_access_key:)
21
+ transfer_manager = Aws::S3::TransferManager.new(client: s3_client)
22
+ status = transfer_manager.upload_file(
23
+ @file_path, bucket:, key:, storage_class: "STANDARD_IA"
24
+ )
25
+ raise S3Error, "Failed AWS S3 upload command" unless status
26
+ end
27
+
28
+ private
29
+
30
+ def validate_call_arguments!(region:, access_key_id:, secret_access_key:, bucket:)
31
+ {
32
+ region:,
33
+ access_key_id:,
34
+ secret_access_key:,
35
+ bucket:
36
+ }.each do |name, value|
37
+ raise ArgumentError, "#{name} is required" if value.nil? || value.to_s.empty?
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Archivault
4
+ class Sqlite
5
+ def initialize(database_path:, backup_path:)
6
+ raise ArgumentError, "database_path is required" if database_path.nil? || database_path.to_s.empty?
7
+ raise ArgumentError, "backup_path is required" if backup_path.nil? || backup_path.to_s.empty?
8
+
9
+ @database_path = database_path.to_s
10
+ @backup_path = backup_path.to_s
11
+ end
12
+
13
+ def call
14
+ Execute.new.call("sqlite3", @database_path, %(.backup "#{@backup_path}"))
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Archivault
4
+ class SqliteBackup
5
+ # Parameters
6
+ # - database_path: Path to the SQLite3 database file
7
+ # - gpg_passphrase: GPG passphrase to encrypt the backup file
8
+ # - s3_setup: Hash of S3 setup options:
9
+ # - region: AWS region
10
+ # - access_key_id: AWS access key ID
11
+ # - secret_access_key: AWS secret access key
12
+ # - bucket: S3 bucket name
13
+ def initialize(database_path:, gpg_passphrase:, s3_setup:, ping_url: nil)
14
+ @database_path = database_path.to_s
15
+ @gpg_passphrase = gpg_passphrase.to_s
16
+ @s3_setup = s3_setup
17
+ @ping_url = ping_url
18
+
19
+ @timestamp = Timestamp.new.timestamp
20
+ @tmp_path = Tmp.new.path
21
+ @backup_path = "#{@tmp_path}/database-#{@timestamp}.sqlite3"
22
+ @tar_path = "#{@tmp_path}/database-#{@timestamp}.tgz"
23
+ @gpg_path = "#{@tar_path}.gpg"
24
+ end
25
+
26
+ def call
27
+ Sqlite.new(database_path: @database_path, backup_path: @backup_path).call
28
+ Tar.new(tar_path: @tar_path, path_or_paths: @backup_path).call
29
+ Gpg.new(@tar_path).call(@gpg_passphrase)
30
+ S3.new(@gpg_path).call(**@s3_setup)
31
+ Ping.new(@ping_url).call if @ping_url
32
+ ensure
33
+ Clean.new([@backup_path, @tar_path, @gpg_path]).call
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Archivault
4
+ class Tar
5
+ def initialize(tar_path:, path_or_paths:)
6
+ raise ArgumentError, "tar_path is required" if tar_path.nil? || tar_path.to_s.empty?
7
+
8
+ @tar_path = tar_path.to_s
9
+
10
+ @paths = Array(path_or_paths)
11
+ raise ArgumentError, "path_or_paths is required" if @paths.empty?
12
+ end
13
+
14
+ def call
15
+ @paths.each do |path|
16
+ raise ArgumentError, "path is required" if path.nil? || path.to_s.empty?
17
+ end
18
+
19
+ Execute.new.call("tar", "-czf", @tar_path, *@paths.map(&:to_s), out: File::NULL, err: File::NULL)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Archivault
4
+ class Timestamp
5
+ attr_reader :timestamp
6
+
7
+ def initialize
8
+ @timestamp = Time.now.strftime("%Y-%m-%d-%H-%M")
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Archivault
4
+ class Tmp
5
+ attr_reader :path
6
+
7
+ def initialize(path = "/tmp")
8
+ @path = defined?(Rails) ? Rails.root.join("tmp").to_s : path
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Archivault
4
+ VERSION = "0.1.0"
5
+ end
data/lib/archivault.rb ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "archivault/version"
4
+ require_relative "archivault/timestamp"
5
+ require_relative "archivault/execute"
6
+ require_relative "archivault/sqlite"
7
+ require_relative "archivault/clean"
8
+ require_relative "archivault/tar"
9
+ require_relative "archivault/tmp"
10
+ require_relative "archivault/gpg"
11
+ require_relative "archivault/s3"
12
+ require_relative "archivault/ping"
13
+ require_relative "archivault/sqlite_backup"
14
+ require_relative "archivault/logs_backup"
15
+
16
+ module Archivault
17
+ class Error < StandardError; end
18
+ class ExecuteError < Error; end
19
+ class S3Error < Error; end
20
+ # Your code goes here...
21
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: archivault
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Piotr Macuk
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: aws-sdk-s3
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.219'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.219'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rexml
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.4'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.4'
40
+ description: ArchiVault is a Ruby gem for Rails applications that backs up files,
41
+ logs, and databases using paths and credentials provided by the app. It compresses
42
+ and encrypts the data, then uploads it securely to AWS S3.
43
+ email:
44
+ - piotr@macuk.pl
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - CHANGELOG.md
50
+ - CODE_OF_CONDUCT.md
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/archivault.rb
55
+ - lib/archivault/clean.rb
56
+ - lib/archivault/execute.rb
57
+ - lib/archivault/gpg.rb
58
+ - lib/archivault/logs_backup.rb
59
+ - lib/archivault/ping.rb
60
+ - lib/archivault/s3.rb
61
+ - lib/archivault/sqlite.rb
62
+ - lib/archivault/sqlite_backup.rb
63
+ - lib/archivault/tar.rb
64
+ - lib/archivault/timestamp.rb
65
+ - lib/archivault/tmp.rb
66
+ - lib/archivault/version.rb
67
+ homepage: https://github.com/macuk/archivault
68
+ licenses:
69
+ - MIT
70
+ metadata:
71
+ homepage_uri: https://github.com/macuk/archivault
72
+ source_code_uri: https://github.com/macuk/archivault
73
+ changelog_uri: https://github.com/macuk/archivault/blob/main/CHANGELOG.md
74
+ rubygems_mfa_required: 'true'
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 3.3.0
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubygems_version: 4.0.9
90
+ specification_version: 4
91
+ summary: Rails backup gem for compressing, encrypting, and uploading data to AWS S3.
92
+ test_files: []