bard-backup 0.13.0 → 0.14.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/CLAUDE.md +2 -2
- data/lib/bard/backup/finder.rb +13 -0
- data/lib/bard/backup/tasks.rake +4 -2
- data/lib/bard/backup/version.rb +1 -1
- data/lib/bard/backup.rb +11 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 500bd736142fc1765b02fdbee4923a35dd4d09bd3cabd825706d7b64b9ad3fff
|
|
4
|
+
data.tar.gz: 07c8d6686725ebd36364da96df0e8f66d80c87ddbf3751e1a86f0e12ead8a78c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f1893706b187e49ad3a16b5fc8fa5a2de0644e522041f7d7a1d4bf9f54054ca8094956a3f26c7a83f7e598097af94726fbbb5d3dc876a5fad90e47e71a2d460d
|
|
7
|
+
data.tar.gz: eb744cd047d227b37de6b723b5e5ec027b8f1c03dd663fc735abfad2165370536a2b727c068b3d5624b64ce9e3ff79b54fc1ea925cfbb30aa6e85ba2ae0cc598
|
data/CLAUDE.md
CHANGED
|
@@ -45,7 +45,7 @@ Tests require AWS credentials at `spec/support/credentials.json`. In CI, this is
|
|
|
45
45
|
**Entry points**:
|
|
46
46
|
- `Bard::Backup.create!` accepts destination configs (or reads from `Bard::Config`) and delegates to destination strategies. Returns a `Bard::Backup` instance with timestamp/size/destinations.
|
|
47
47
|
- `Bard::Backup::FileTree.create!` syncs configured data directories to S3.
|
|
48
|
-
- `Bard::Backup.restore!(at:)` downloads the backup nearest `at` (or the latest when omitted), decrypts it if necessary, and loads it into the local database via `backhoe` (drop-and-create). `Bard::Backup.available` lists the available
|
|
48
|
+
- `Bard::Backup.restore!(at:)` downloads the backup nearest `at` (or the latest when omitted), decrypts it if necessary, and loads it into the local database via `backhoe` (drop-and-create). `Bard::Backup.available` lists the available backups (as `Bard::Backup` objects carrying timestamp and size).
|
|
49
49
|
|
|
50
50
|
**Destination strategy pattern**: `Destination.build(config)` is a factory that picks the right class based on `:type`. `Destination.resolve(hashes)` is the single entry point both `Database.create!` and `Finder` use — it falls back to the configured destinations, normalizes a lone Hash/Array, and builds them. Each destination resolves its own `encryption_key` (explicit config, falling back to `Bard::Config.current.backup.encryption_key`), so callers never inject it.
|
|
51
51
|
- `S3Destination` — dumps DB locally via backhoe, uploads to S3, runs `Deleter` for retention, verifies previous hour's backup
|
|
@@ -65,7 +65,7 @@ end
|
|
|
65
65
|
- `Encryptor` — AES-256-GCM with HKDF-derived keys and a deterministic IV (HMAC of plaintext), enabling content-addressable encryption
|
|
66
66
|
- `Deleter` — implements the retention policy via `Filter` structs that check time-based granularities
|
|
67
67
|
- `LocalBackhoe` / `CachedLocalBackhoe` — database dump strategies (cached variant avoids conflicts when running parallel destinations)
|
|
68
|
-
- `Finder` — lists backups across destinations and selects one: by timestamp (nearest match), the latest, or the most-recent as a `Bard::Backup` (with size + destination info). Backs `Bard::Backup.available`/`.latest` and `Restore`
|
|
68
|
+
- `Finder` — lists backups across destinations and selects one: by timestamp (nearest match), the latest, or the most-recent as a `Bard::Backup` (with size + destination info). `#available` returns one `Bard::Backup` per timestamp (with size) for listing. Backs `Bard::Backup.available`/`.latest` and `Restore`
|
|
69
69
|
- `Restore` — downloads the backup selected by `Finder`, decrypts it via `S3Tree#get`, and loads it into the local database via backhoe (drop-and-create). Backs `Bard::Backup.restore!`
|
|
70
70
|
- `BackupConfig` — the `backup do ... end` DSL surface (`bard`, `disabled`, `s3 name, **kwargs`); `create!` reads `bard_config.backup.destinations` from it
|
|
71
71
|
- `Railtie` — loads `tasks.rake` which provides `bard:backup` (DB + data), `bard:backup:data` (data only), and `bard:backup:restore[at]` (restore/list) rake tasks in Rails apps
|
data/lib/bard/backup/finder.rb
CHANGED
|
@@ -26,6 +26,19 @@ module Bard
|
|
|
26
26
|
all.map { |backup| backup[:timestamp] }.uniq.sort
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
+
def available
|
|
30
|
+
all
|
|
31
|
+
.group_by { |backup| backup[:timestamp] }
|
|
32
|
+
.sort_by { |timestamp, _| timestamp }
|
|
33
|
+
.map do |timestamp, backups|
|
|
34
|
+
Bard::Backup.new(
|
|
35
|
+
timestamp:,
|
|
36
|
+
size: file_size(backups.first[:destination].s3_tree, backups.first[:filename]),
|
|
37
|
+
destinations: backups.map { |backup| backup[:destination].info },
|
|
38
|
+
)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
29
42
|
def find(at: nil)
|
|
30
43
|
backups = all
|
|
31
44
|
raise NotFound, "No backups found" if backups.empty?
|
data/lib/bard/backup/tasks.rake
CHANGED
|
@@ -26,9 +26,11 @@ namespace :bard do
|
|
|
26
26
|
|
|
27
27
|
destinations = Bard::Config.current.backup.destinations
|
|
28
28
|
if args[:at].to_s.strip.empty?
|
|
29
|
-
|
|
29
|
+
backups = Bard::Backup.available(destinations: destinations)
|
|
30
30
|
puts "Available backups:"
|
|
31
|
-
|
|
31
|
+
backups.each do |backup|
|
|
32
|
+
puts " #{backup.timestamp.iso8601} #{backup.human_size}"
|
|
33
|
+
end
|
|
32
34
|
else
|
|
33
35
|
backup = Bard::Backup.restore!(at: args[:at], destinations: destinations)
|
|
34
36
|
puts "Restored database from backup #{backup.timestamp.iso8601}."
|
data/lib/bard/backup/version.rb
CHANGED
data/lib/bard/backup.rb
CHANGED
|
@@ -22,7 +22,7 @@ module Bard
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def self.available(destinations: nil)
|
|
25
|
-
Finder.new(destinations).
|
|
25
|
+
Finder.new(destinations).available
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def self.restore!(at:, drop_and_create: true, destinations: nil)
|
|
@@ -44,5 +44,15 @@ module Bard
|
|
|
44
44
|
destinations: destinations
|
|
45
45
|
}.compact
|
|
46
46
|
end
|
|
47
|
+
|
|
48
|
+
def human_size
|
|
49
|
+
units = %w[Bytes KB MB GB TB PB EB]
|
|
50
|
+
value, unit = size.to_f, 0
|
|
51
|
+
while value >= 1024 && unit < units.size - 1
|
|
52
|
+
value /= 1024
|
|
53
|
+
unit += 1
|
|
54
|
+
end
|
|
55
|
+
format("%5.2f %s", value, units[unit])
|
|
56
|
+
end
|
|
47
57
|
end
|
|
48
58
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bard-backup
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.14.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Micah Geisel
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-07-
|
|
10
|
+
date: 2026-07-13 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: backhoe
|