kamal-backup 0.4.2 → 0.5.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: 0442e12748359ee182d6fc91e5573375440c31a5a65ccf1b46079547b8e4bc21
4
- data.tar.gz: 9af03ddf3ad23b99b77c717711dc66cde34bc17500e66e776aff50ca2678e653
3
+ metadata.gz: aa8276219db8c5d8aa820e85e0f289f87715889cb5ea18ae2c99e3e12bbfe6b9
4
+ data.tar.gz: 626824ed56029bf3b713676d3376ab38d571942ee3809e7cf18abbfde9c24a45
5
5
  SHA512:
6
- metadata.gz: ccd324da250d8a36f623a6c65c9cf000c80e4fbcc0308944c1074c67ce9422e1e637c55e672160399078944c83c281ccec25ff17a63d1181ed28045244a2d674
7
- data.tar.gz: 80f64be478843d1695cdfa34c899ba614ee7ed45a10853f521c08ee568f003f3b0045809ef1ff0c1217e5ec834d2a607888963998af64f9643886048f0e65bf1
6
+ metadata.gz: 75d362d35409c0447c29994a7bf4d23ac47d287fc88621eb46f32a56296537217cee76a28799983f45154361ecd61e4f553b609144969bed2b10016bf0ecc09c
7
+ data.tar.gz: e5f664a15123066441b940d945caed2335d8b50356acaa64d9ae6f49d87a7705894234e55db42ec6508aa188f727b01d4e4d4c71688ecd93b4dbf4c12d53ef5d
@@ -32,6 +32,7 @@ module KamalBackup
32
32
  def backup(force: false)
33
33
  started_at = Time.now.utc
34
34
  config.validate_backup
35
+ return disabled_backup_result(started_at) unless config.backup_enabled? || force
35
36
  return skipped_backup_result(started_at) unless force || backup_due?(started_at)
36
37
 
37
38
  restic.ensure_repository
@@ -136,6 +137,18 @@ module KamalBackup
136
137
  due_at.nil? || now >= due_at
137
138
  end
138
139
 
140
+ def disabled_backup_result(now)
141
+ Schema.record(
142
+ kind: 'backup_result',
143
+ status: 'skipped',
144
+ reason: 'disabled',
145
+ last_backup_at: last_backup_finished_at&.iso8601,
146
+ next_backup_at: nil,
147
+ force_command: 'kamal-backup backup --force',
148
+ finished_at: now.iso8601
149
+ )
150
+ end
151
+
139
152
  def skipped_backup_result(now)
140
153
  Schema.record(
141
154
  kind: 'backup_result',
@@ -140,6 +140,13 @@ module KamalBackup
140
140
  end
141
141
 
142
142
  def print_backup_result(result)
143
+ if result[:status] == 'skipped' && result[:reason] == 'disabled'
144
+ puts('Backups are disabled for this app (backup.enabled is false).')
145
+ puts('Set backup.enabled to true and redeploy the accessory to resume scheduled backups.')
146
+ puts("Run `#{result.fetch(:force_command)}` to take one anyway.")
147
+ return
148
+ end
149
+
143
150
  if result[:status] == 'skipped'
144
151
  puts("No backup due. Last backup finished at #{result.fetch(:last_backup_at)}.")
145
152
  puts("Next backup is due at #{result.fetch(:next_backup_at)}.")
@@ -168,6 +168,10 @@ module KamalBackup
168
168
  truthy?('KAMAL_BACKUP_ALLOW_SUSPICIOUS_PATHS')
169
169
  end
170
170
 
171
+ def backup_enabled?
172
+ !falsey?('BACKUP_ENABLED')
173
+ end
174
+
171
175
  def backup_schedule_seconds
172
176
  integer('BACKUP_SCHEDULE_SECONDS', 86_400, minimum: 1)
173
177
  end
@@ -271,6 +271,7 @@ module KamalBackup
271
271
  hash = require_mapping(raw_value, "#{@path} backup")
272
272
  env = {}
273
273
  env['BACKUP_SCHEDULE_SECONDS'] = normalize_duration(hash['schedule'], "#{@path} backup.schedule") if hash.key?('schedule')
274
+ env['BACKUP_ENABLED'] = normalize_value(hash['enabled']) if hash.key?('enabled')
274
275
  env.compact
275
276
  end
276
277
 
@@ -15,6 +15,17 @@ module KamalBackup
15
15
  $stderr.sync = true
16
16
 
17
17
  install_signal_handlers
18
+
19
+ unless @config.backup_enabled?
20
+ # Stay up rather than exit: the accessory is still how restore, list, check and
21
+ # evidence reach the repository, and exiting would restart-loop under Kamal's
22
+ # `--restart unless-stopped`. Set backup.enabled to true and redeploy to resume.
23
+ log('scheduled backups are disabled (backup.enabled is false); no backups will be taken')
24
+ idle_until_stopped
25
+ log("scheduler stopped at #{Time.now.utc.iso8601}")
26
+ return
27
+ end
28
+
18
29
  sleep_interruptibly(@config.backup_start_delay_seconds)
19
30
 
20
31
  until @stop
@@ -43,6 +54,10 @@ module KamalBackup
43
54
  end
44
55
  end
45
56
 
57
+ def idle_until_stopped
58
+ sleep 1 until @stop
59
+ end
60
+
46
61
  def sleep_interruptibly(seconds)
47
62
  deadline = Time.now + seconds
48
63
  sleep([deadline - Time.now, 1].min) while !@stop && Time.now < deadline
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KamalBackup
4
- VERSION = '0.4.2'
4
+ VERSION = '0.5.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kamal-backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - crmne