bareos-restore 1.0.0 → 1.0.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bareos-restore.rb +41 -6
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d77f4b6e3042c4e2453c5ed4ab9842d62da720b161024298bb0c3394daf2f931
4
- data.tar.gz: 127cc098dd8b2002d504fbaa7cb82fcf9c2f8d4970488cff8e2cbf62494b1133
3
+ metadata.gz: 216f631eff362fc9f5f3a80f434f86bb5353b14fb94165353ab6f9df4c42eca8
4
+ data.tar.gz: 9b8c4cad97d5756ac529a45de778e99bf680b43956c325b10bfddf39e60862bc
5
5
  SHA512:
6
- metadata.gz: b8baad71dfec5b5107ff71141e181d22405f87203e7184810b95555d630f3c88bf45fcb3c0b52bcd47cea0156e763100da4a2ce0be878ceef33066d570db2efc
7
- data.tar.gz: ff2989fea490a11247003dfebc343226caf305d018889bf24da73da0f04a1f91f56b640419a3eb94db68b22b7a33ba228bee828ab4b934da0f12b27105fa7355
6
+ metadata.gz: ffca43d03edbb7956862d659ddf7499836a0ce41b0ef07e62b15a3fa0e6a88b920483d897472e2eb4a9db0a8b2a867b2e9f338a613a4ca04548392dd09fbbfda
7
+ data.tar.gz: cba949d1bf989c36dbbf2002e56840b19a0ba738a91d84b1355bdf4ce910a7f596b2d6512276cad109398f5f436410af974eb79b9cb2d4f2c016a16384ffaea8
@@ -13,9 +13,11 @@ require 'expect'
13
13
  require 'time'
14
14
  require 'logger'
15
15
 
16
- # Bareos bconsole configuration
16
+ # Path to bconsole
17
17
  BCONSOLE_PATH = '/usr/sbin/bconsole'
18
18
 
19
+ # Mapping of job status bytes (e.g. "C") to meaningful states (pending/running/failed)
20
+ # and a human-readable text.
19
21
  JOBSTATUS = {
20
22
  C: {
21
23
  text: 'Created, not yet running',
@@ -180,10 +182,25 @@ module BareosRestore
180
182
  $logger.level = Logger::INFO
181
183
  #$logger.level = Logger::DEBUG
182
184
 
183
- # Function to run a command in bconsole
184
- # Sends input commands to bconsole and captures the output
185
- # apilevel=1 -> Text-based output
186
- # apilevel=2 -> JSON-based output
185
+ # Executes a command in the Bacula console (bconsole).
186
+ # It only supports one-shot commands. If you want to do complex tasks like
187
+ # restoring files, you need to specify all parameters to make the restore
188
+ # job start without getting asked further questions. The communication is
189
+ # not interactive.
190
+ #
191
+ # @param command [String] The Bacula console command to execute
192
+ #
193
+ # @param apilevel [Integer] The API level (1 for text, 2 for JSON, default: 2)
194
+ #
195
+ # @return [String, Hash] Text output for level 1, parsed JSON for level 2
196
+ #
197
+ # @example Text output
198
+ #
199
+ # bconsole("status jobid=12345", apilevel: 1) => "…"
200
+ #
201
+ # @example JSON output
202
+ #
203
+ # bconsole("status jobid=12345") #=> { "status": "running" }
187
204
  def self.bconsole(command, apilevel: 2)
188
205
  bconsole_cmd = ".api #{apilevel}\n#{command}\n"
189
206
  output = nil
@@ -209,6 +226,11 @@ module BareosRestore
209
226
  raise "Error parsing JSON: #{e.message}"
210
227
  end
211
228
 
229
+ # Get the Job ID of the last run backup job.
230
+ #
231
+ # @param backup_name [String] Name of the backup job.
232
+ #
233
+ # @return [Integer] job ID
212
234
  def self.latest_jobid(backup_name)
213
235
  $logger.info "Getting latest job ID for backup #{backup_name}"
214
236
  $logger.info "list jobs job=#{backup_name} jobstatus=T jobtype=B last"
@@ -218,6 +240,11 @@ module BareosRestore
218
240
  output['jobs'].first['jobid']
219
241
  end
220
242
 
243
+ # Get the log messages of a Bareos job. It uses `get joblog jobid=…` in the background.
244
+ #
245
+ # @param job_id [Integer] ID of the backup/restore job
246
+ #
247
+ # @return [String] job's log if the job succeeded
221
248
  def self.get_joblog(job_id)
222
249
  $logger.info "Getting job log for job #{job_id}"
223
250
  output = bconsole "list joblog jobid=#{job_id}"
@@ -228,7 +255,15 @@ module BareosRestore
228
255
  $logger.info "JOBLOG…\n#{textblock.join("\n")}"
229
256
  end
230
257
 
231
- # Function to initiate restore and wait for job completion
258
+ # Start a restore job and wait for its completion.
259
+ #
260
+ # @param job_id [Integer] ID of the backup job
261
+ #
262
+ # @param target_directory [String] Destination directory to restore the files
263
+ #
264
+ # @param restore_client [String] Bareos client/file-daemon used to restore the files
265
+ #
266
+ # @return [String] job's log if the job succeeded (exits with non-zero code otherwise)
232
267
  def self.perform_restore(job_id, restore_dir, bareos_client)
233
268
  $logger.info "Gathering Full/Diff/Incr jobs to get a complete restore of Job ID #{job_id}"
234
269
  output = bconsole ".bvfs_get_jobids jobid=#{job_id}"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bareos-restore
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christoph Haas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-03 00:00:00.000000000 Z
11
+ date: 2025-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sys-filesystem