archivault 0.2.1 → 0.3.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/archivault/execute.rb +2 -2
- data/lib/archivault/logs_backup.rb +1 -2
- data/lib/archivault/pg_dump.rb +17 -2
- data/lib/archivault/postgresql_backup.rb +1 -2
- data/lib/archivault/sqlite_backup.rb +1 -2
- data/lib/archivault/timestamp.rb +8 -0
- data/lib/archivault/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a4ec8f7f88e54372cf70eb0e07e637c34561ddc888ec4ef4ccb53275c64d3993
|
|
4
|
+
data.tar.gz: 8b89b5f12ae91effaad05cf5add3ce8a0e58bd43cce1ac0d7482505f751ac464
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 03cf209ecb7fbc7f1bb6af70ecc290d9ca302aa63bd6c4d07c07ad0605d0cccf42d44680a5ca3beb3ae80e63299aa965177b708ca1bc22015bdb041f319b0706
|
|
7
|
+
data.tar.gz: c3232861b94738f32449782c035df357d4ef2ab94859c848821b7ec8af450daf490a93e2a0543a79978d3c8e1628c570a48ec6421ce7fbd0848e265b5f558d6f
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
- Add an unguessable random suffix to backup file names, so a PutObject-only S3 key cannot target (overwrite) existing backups
|
|
4
|
+
- Pass decoded PostgreSQL URL passwords to pg_dump through PGPASSWORD instead of command-line arguments, and prevent password leaks in invalid URL errors
|
|
5
|
+
- Allow Execute to forward environment variables and system options
|
|
6
|
+
|
|
3
7
|
## [0.2.1] - 2026-09-03
|
|
4
8
|
|
|
5
9
|
- Allow custom database backup filename prefixes
|
data/lib/archivault/execute.rb
CHANGED
|
@@ -4,8 +4,8 @@ require "English"
|
|
|
4
4
|
|
|
5
5
|
module Archivault
|
|
6
6
|
class Execute
|
|
7
|
-
def call(command,
|
|
8
|
-
status = system(command,
|
|
7
|
+
def call(command, *, env: {}, **)
|
|
8
|
+
status = system(env, command, *, **)
|
|
9
9
|
raise ExecuteError, "#{command} could not be executed" if status.nil?
|
|
10
10
|
raise ExecuteError, "#{command} failed with exit code #{$CHILD_STATUS&.exitstatus}" unless status
|
|
11
11
|
|
|
@@ -16,9 +16,8 @@ module Archivault
|
|
|
16
16
|
@s3_setup = s3_setup
|
|
17
17
|
@ping_url = ping_url
|
|
18
18
|
|
|
19
|
-
@timestamp = Timestamp.new.timestamp
|
|
20
19
|
@tmp_path = Tmp.new.path
|
|
21
|
-
@tar_path = "#{@tmp_path}
|
|
20
|
+
@tar_path = "#{@tmp_path}/#{Timestamp.new.backup_name("logs")}.tgz"
|
|
22
21
|
@gpg_path = "#{@tar_path}.gpg"
|
|
23
22
|
end
|
|
24
23
|
|
data/lib/archivault/pg_dump.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# To restore a database from a dump file, use:
|
|
4
|
-
# pg_restore --no-owner -d
|
|
4
|
+
# pg_restore --clean --if-exists --no-owner --no-acl --role=db-role -U postgres -d db-name /tmp/db.dump
|
|
5
5
|
module Archivault
|
|
6
6
|
class PgDump
|
|
7
7
|
def initialize(database_url:, backup_path:)
|
|
@@ -12,8 +12,23 @@ module Archivault
|
|
|
12
12
|
@backup_path = backup_path.to_s
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
+
# The password goes to pg_dump through PGPASSWORD, not through the command line:
|
|
16
|
+
# arguments of a running process are readable by every local user (ps, /proc/<pid>/cmdline).
|
|
15
17
|
def call
|
|
16
|
-
|
|
18
|
+
uri = parse_database_url
|
|
19
|
+
password = URI.decode_uri_component(uri.password) if uri.password && !uri.password.empty?
|
|
20
|
+
uri.password = nil
|
|
21
|
+
env = password ? { "PGPASSWORD" => password } : {}
|
|
22
|
+
Execute.new.call("pg_dump", "-Fc", "-f", @backup_path, uri.to_s, env: env)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def parse_database_url
|
|
28
|
+
URI.parse(@database_url)
|
|
29
|
+
rescue URI::InvalidURIError
|
|
30
|
+
# URI::InvalidURIError quotes the whole input, password included - re-raise without it.
|
|
31
|
+
raise "Invalid database URL: percent-encode special characters in the password", cause: nil
|
|
17
32
|
end
|
|
18
33
|
end
|
|
19
34
|
end
|
|
@@ -17,9 +17,8 @@ module Archivault
|
|
|
17
17
|
@s3_setup = s3_setup
|
|
18
18
|
@ping_url = ping_url
|
|
19
19
|
|
|
20
|
-
@timestamp = Timestamp.new.timestamp
|
|
21
20
|
@tmp_path = Tmp.new.path
|
|
22
|
-
backup_filename =
|
|
21
|
+
backup_filename = Timestamp.new.backup_name(filename || "database")
|
|
23
22
|
@backup_path = "#{@tmp_path}/#{backup_filename}.dump"
|
|
24
23
|
@tar_path = "#{@tmp_path}/#{backup_filename}.tgz"
|
|
25
24
|
@gpg_path = "#{@tar_path}.gpg"
|
|
@@ -17,9 +17,8 @@ module Archivault
|
|
|
17
17
|
@s3_setup = s3_setup
|
|
18
18
|
@ping_url = ping_url
|
|
19
19
|
|
|
20
|
-
@timestamp = Timestamp.new.timestamp
|
|
21
20
|
@tmp_path = Tmp.new.path
|
|
22
|
-
backup_filename =
|
|
21
|
+
backup_filename = Timestamp.new.backup_name(filename || "database")
|
|
23
22
|
@backup_path = "#{@tmp_path}/#{backup_filename}.sqlite3"
|
|
24
23
|
@tar_path = "#{@tmp_path}/#{backup_filename}.tgz"
|
|
25
24
|
@gpg_path = "#{@tar_path}.gpg"
|
data/lib/archivault/timestamp.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "securerandom"
|
|
4
|
+
|
|
3
5
|
module Archivault
|
|
4
6
|
class Timestamp
|
|
5
7
|
attr_reader :timestamp
|
|
@@ -7,5 +9,11 @@ module Archivault
|
|
|
7
9
|
def initialize
|
|
8
10
|
@timestamp = Time.now.strftime("%Y-%m-%d-%H-%M")
|
|
9
11
|
end
|
|
12
|
+
|
|
13
|
+
# The backup S3 key may only PutObject, which can also overwrite an existing object.
|
|
14
|
+
# It can't list the bucket, so an unguessable suffix keeps it from targeting existing backups.
|
|
15
|
+
def backup_name(prefix)
|
|
16
|
+
"#{prefix}-#{timestamp}-#{SecureRandom.hex(8)}"
|
|
17
|
+
end
|
|
10
18
|
end
|
|
11
19
|
end
|
data/lib/archivault/version.rb
CHANGED