archivault 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18e7063c221d22627d0355b857c7bd767d14cd2312f2c04391c506cba4ba1689
4
- data.tar.gz: 2b5649d48fc0eb996bc8377f7670ad1d576cfe18609363079653472f92bea66c
3
+ metadata.gz: eaf47c3cfc367a25c1ea685a22229738230844f458187e7094bbb1892a80c67d
4
+ data.tar.gz: ce10a4fa42f6c2e9b2a52938f11884e82828351ccfedb540bce4402b747334a3
5
5
  SHA512:
6
- metadata.gz: 2de400dc93463d3dd8247eaecdb9a323c59001106e1ad41d145dba5b68d50f03ec8ab2bde6fb7b98b128280a2dee21439bb4340d5a068810f654b91f586b488a
7
- data.tar.gz: 9a41e8bec7f152ba8ee845e5387dfabcda6f7055ba770c012d1143da1ac81454039d20448b5b74e77527859100f51a21d0582f3af685bbe6187fcd193789fac2
6
+ metadata.gz: ca08c17fb2a4f21a0bc2e200fe9ea931b60b5057856b38e2725fe57b2de37f424a35f2cb181052f4dda613a1f45547fd10fc08ba04ce27d3135a02c5dd404109
7
+ data.tar.gz: c1ab9e98d5b9ca7072d18cfe352f32d2074f6401c28b5c199cab83a9d9f076a8e186878ce63466ae823aaa87cd79142a75fcb464f358054349978403e1227e3e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2026-04-10
4
+
5
+ - Add PostgresqlBackup
6
+
3
7
  ## [0.1.0] - 2026-04-08
4
8
 
5
9
  - Initial release
data/README.md CHANGED
@@ -36,6 +36,22 @@ ping_url = "https://example.com/ping" # optional parameter
36
36
  Archivault::SqliteBackup.new(database_path:, gpg_passphrase:, s3_setup:, ping_url:).call
37
37
  ```
38
38
 
39
+ ### PostgreSQL database backup
40
+
41
+ ```ruby
42
+ database_url = "postgres://user:password@localhost:5432/mydb"
43
+ gpg_passphrase = "password"
44
+ s3_setup = {
45
+ region: "region",
46
+ access_key_id: "access_key_id",
47
+ secret_access_key: "secret_access_key",
48
+ bucket: "bucket"
49
+ }
50
+ ping_url = "https://example.com/ping" # optional parameter
51
+
52
+ Archivault::PostgresqlBackup.new(database_url:, gpg_passphrase:, s3_setup:, ping_url:).call
53
+ ```
54
+
39
55
  ### Logs backup
40
56
 
41
57
  ```ruby
@@ -55,7 +71,7 @@ ping_url = "https://example.com/ping" # optional parameter
55
71
  Archivault::LogsBackup.new(log_path_or_paths:, gpg_passphrase:, s3_setup:, ping_url:).call
56
72
  ```
57
73
 
58
- ## Rais usage
74
+ ## Rails usage
59
75
 
60
76
  ### SQLite database backup
61
77
 
@@ -75,6 +91,24 @@ params = {
75
91
  Archivault::SqliteBackup.new(**params).call
76
92
  ```
77
93
 
94
+ ### PostgreSQL database backup
95
+
96
+ ```ruby
97
+ # in config/credentials.yml.enc
98
+ # archivault:
99
+ # gpg_passphrase: password
100
+ # s3_setup:
101
+ # region: region
102
+ # access_key_id: access_key_id
103
+ # secret_access_key: secret_access_key
104
+ # bucket: bucket
105
+ params = {
106
+ database_url: ENV["DATABASE_URL"],
107
+ ping_url: "https://example.com/ping" # optional parameter
108
+ }.merge(Rails.application.credentials.archivault)
109
+ Archivault::PostgresqlBackup.new(**params).call
110
+ ```
111
+
78
112
  ### Logs backup
79
113
 
80
114
  ```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,36 @@
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
+ def initialize(database_url:, gpg_passphrase:, s3_setup:, ping_url: nil)
14
+ @database_url = database_url.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}.dump"
22
+ @tar_path = "#{@tmp_path}/database-#{@timestamp}.tgz"
23
+ @gpg_path = "#{@tar_path}.gpg"
24
+ end
25
+
26
+ def call
27
+ PgDump.new(database_url: @database_url, 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
@@ -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.0"
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.0
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