archivault 0.1.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18e7063c221d22627d0355b857c7bd767d14cd2312f2c04391c506cba4ba1689
4
- data.tar.gz: 2b5649d48fc0eb996bc8377f7670ad1d576cfe18609363079653472f92bea66c
3
+ metadata.gz: 2c3fafb7a999944ce6e513420f1e90a1f842a7460c6364d69b71a9d6158b8453
4
+ data.tar.gz: 325edbcd21420a5079857f8e317a292587787579d3580e819c6da8dc93cac5ce
5
5
  SHA512:
6
- metadata.gz: 2de400dc93463d3dd8247eaecdb9a323c59001106e1ad41d145dba5b68d50f03ec8ab2bde6fb7b98b128280a2dee21439bb4340d5a068810f654b91f586b488a
7
- data.tar.gz: 9a41e8bec7f152ba8ee845e5387dfabcda6f7055ba770c012d1143da1ac81454039d20448b5b74e77527859100f51a21d0582f3af685bbe6187fcd193789fac2
6
+ metadata.gz: 7901b70a33e62c64bce142a02437a2ffbe520249b56ccc899403e2068f7e34fdb5c23189af5c9d65c9c0ba7e5844d04bcbf088a3b095bf28054b12d82edc709f
7
+ data.tar.gz: e6e05ca1b5671138ad04ab9a1f349cf4401912e7c22816b49826f0a740f63105be7178b0305275be7e3505086e9adda48c75bce2ee11683b5b20e931f2f7d511
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.1] - 2026-09-03
4
+
5
+ - Allow custom database backup filename prefixes
6
+
7
+ ## [0.2.0] - 2026-04-10
8
+
9
+ - Add PostgresqlBackup
10
+
3
11
  ## [0.1.0] - 2026-04-08
4
12
 
5
13
  - Initial release
data/README.md CHANGED
@@ -32,8 +32,26 @@ s3_setup = {
32
32
  bucket: "bucket"
33
33
  }
34
34
  ping_url = "https://example.com/ping" # optional parameter
35
+ filename = "production" # optional prefix; timestamp is appended
35
36
 
36
- Archivault::SqliteBackup.new(database_path:, gpg_passphrase:, s3_setup:, ping_url:).call
37
+ Archivault::SqliteBackup.new(database_path:, gpg_passphrase:, s3_setup:, ping_url:, filename:).call
38
+ ```
39
+
40
+ ### PostgreSQL database backup
41
+
42
+ ```ruby
43
+ database_url = "postgres://user:password@localhost:5432/mydb"
44
+ gpg_passphrase = "password"
45
+ s3_setup = {
46
+ region: "region",
47
+ access_key_id: "access_key_id",
48
+ secret_access_key: "secret_access_key",
49
+ bucket: "bucket"
50
+ }
51
+ ping_url = "https://example.com/ping" # optional parameter
52
+ filename = "production" # optional prefix; timestamp is appended
53
+
54
+ Archivault::PostgresqlBackup.new(database_url:, gpg_passphrase:, s3_setup:, ping_url:, filename:).call
37
55
  ```
38
56
 
39
57
  ### Logs backup
@@ -55,7 +73,7 @@ ping_url = "https://example.com/ping" # optional parameter
55
73
  Archivault::LogsBackup.new(log_path_or_paths:, gpg_passphrase:, s3_setup:, ping_url:).call
56
74
  ```
57
75
 
58
- ## Rais usage
76
+ ## Rails usage
59
77
 
60
78
  ### SQLite database backup
61
79
 
@@ -70,11 +88,31 @@ Archivault::LogsBackup.new(log_path_or_paths:, gpg_passphrase:, s3_setup:, ping_
70
88
  # bucket: bucket
71
89
  params = {
72
90
  database_path: Rails.root.join("storage/production.sqlite3"),
73
- ping_url: "https://example.com/ping" # optional parameter
91
+ ping_url: "https://example.com/ping", # optional parameter
92
+ filename: "production" # optional prefix; timestamp is appended
74
93
  }.merge(Rails.application.credentials.archivault)
75
94
  Archivault::SqliteBackup.new(**params).call
76
95
  ```
77
96
 
97
+ ### PostgreSQL database backup
98
+
99
+ ```ruby
100
+ # in config/credentials.yml.enc
101
+ # archivault:
102
+ # gpg_passphrase: password
103
+ # s3_setup:
104
+ # region: region
105
+ # access_key_id: access_key_id
106
+ # secret_access_key: secret_access_key
107
+ # bucket: bucket
108
+ params = {
109
+ database_url: ENV["DATABASE_URL"],
110
+ ping_url: "https://example.com/ping", # optional parameter
111
+ filename: "production" # optional prefix; timestamp is appended
112
+ }.merge(Rails.application.credentials.archivault)
113
+ Archivault::PostgresqlBackup.new(**params).call
114
+ ```
115
+
78
116
  ### Logs backup
79
117
 
80
118
  ```ruby
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # To decrypt encrypted file, use:
4
+ # gpg --output output.txt --decrypt output.txt.gpg
3
5
  module Archivault
4
6
  class Gpg
5
7
  def initialize(file_path)
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # To restore a database from a dump file, use:
4
+ # pg_restore --no-owner -d DATABASE_URL database.dump
5
+ module Archivault
6
+ class PgDump
7
+ def initialize(database_url:, backup_path:)
8
+ raise ArgumentError, "database_path is required" if database_url.nil? || database_url.to_s.empty?
9
+ raise ArgumentError, "backup_path is required" if backup_path.nil? || backup_path.to_s.empty?
10
+
11
+ @database_url = database_url.to_s
12
+ @backup_path = backup_path.to_s
13
+ end
14
+
15
+ def call
16
+ Execute.new.call("pg_dump", "-Fc", "-f", @backup_path, @database_url)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Archivault
4
+ class PostgresqlBackup
5
+ # Parameters
6
+ # - database_url: Database URL
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
+ # - filename: Filename prefix for the backup (defaults to database)
14
+ def initialize(database_url:, gpg_passphrase:, s3_setup:, ping_url: nil, filename: nil)
15
+ @database_url = database_url.to_s
16
+ @gpg_passphrase = gpg_passphrase.to_s
17
+ @s3_setup = s3_setup
18
+ @ping_url = ping_url
19
+
20
+ @timestamp = Timestamp.new.timestamp
21
+ @tmp_path = Tmp.new.path
22
+ backup_filename = "#{filename || "database"}-#{@timestamp}"
23
+ @backup_path = "#{@tmp_path}/#{backup_filename}.dump"
24
+ @tar_path = "#{@tmp_path}/#{backup_filename}.tgz"
25
+ @gpg_path = "#{@tar_path}.gpg"
26
+ end
27
+
28
+ def call
29
+ PgDump.new(database_url: @database_url, backup_path: @backup_path).call
30
+ Tar.new(tar_path: @tar_path, path_or_paths: @backup_path).call
31
+ Gpg.new(@tar_path).call(@gpg_passphrase)
32
+ S3.new(@gpg_path).call(**@s3_setup)
33
+ Ping.new(@ping_url).call if @ping_url
34
+ ensure
35
+ Clean.new([@backup_path, @tar_path, @gpg_path]).call
36
+ end
37
+ end
38
+ end
@@ -10,7 +10,8 @@ module Archivault
10
10
  # - access_key_id: AWS access key ID
11
11
  # - secret_access_key: AWS secret access key
12
12
  # - bucket: S3 bucket name
13
- def initialize(database_path:, gpg_passphrase:, s3_setup:, ping_url: nil)
13
+ # - filename: Filename prefix for the backup (defaults to database)
14
+ def initialize(database_path:, gpg_passphrase:, s3_setup:, ping_url: nil, filename: nil)
14
15
  @database_path = database_path.to_s
15
16
  @gpg_passphrase = gpg_passphrase.to_s
16
17
  @s3_setup = s3_setup
@@ -18,8 +19,9 @@ module Archivault
18
19
 
19
20
  @timestamp = Timestamp.new.timestamp
20
21
  @tmp_path = Tmp.new.path
21
- @backup_path = "#{@tmp_path}/database-#{@timestamp}.sqlite3"
22
- @tar_path = "#{@tmp_path}/database-#{@timestamp}.tgz"
22
+ backup_filename = "#{filename || "database"}-#{@timestamp}"
23
+ @backup_path = "#{@tmp_path}/#{backup_filename}.sqlite3"
24
+ @tar_path = "#{@tmp_path}/#{backup_filename}.tgz"
23
25
  @gpg_path = "#{@tar_path}.gpg"
24
26
  end
25
27
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Archivault
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/archivault.rb CHANGED
@@ -10,8 +10,10 @@ require_relative "archivault/tmp"
10
10
  require_relative "archivault/gpg"
11
11
  require_relative "archivault/s3"
12
12
  require_relative "archivault/ping"
13
+ require_relative "archivault/pg_dump"
13
14
  require_relative "archivault/sqlite_backup"
14
15
  require_relative "archivault/logs_backup"
16
+ require_relative "archivault/postgresql_backup"
15
17
 
16
18
  module Archivault
17
19
  class Error < StandardError; end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: archivault
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Macuk
@@ -56,7 +56,9 @@ files:
56
56
  - lib/archivault/execute.rb
57
57
  - lib/archivault/gpg.rb
58
58
  - lib/archivault/logs_backup.rb
59
+ - lib/archivault/pg_dump.rb
59
60
  - lib/archivault/ping.rb
61
+ - lib/archivault/postgresql_backup.rb
60
62
  - lib/archivault/s3.rb
61
63
  - lib/archivault/sqlite.rb
62
64
  - lib/archivault/sqlite_backup.rb