Module: PrlBackup

Included in:
Backup, Backup, VirtualMachine, VirtualMachine
Defined in:
lib/prlbackup.rb,
lib/prlbackup/cli.rb,
lib/prlbackup/backup.rb,
lib/prlbackup/version.rb,
lib/prlbackup/virtual_machine.rb

Defined Under Namespace

Classes: Backup, CLI, VirtualMachine

Constant Summary collapse

VERSION =
'1.3.0'

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.configObject

The global configuration based on command line options.



13
14
15
# File 'lib/prlbackup.rb', line 13

def config
  @config
end

Instance Method Details

#conditionally_run(*args) ⇒ String

Run the command and log the last line from stdout unless –dry-run.

Returns:

  • (String)

    stdout of the comand.



18
19
20
21
22
23
24
25
26
27
# File 'lib/prlbackup.rb', line 18

def conditionally_run(*args)
  unless PrlBackup.config[:dry_run]
    output = run(*args)
    logger.info(output.split("\n").last)
  else
    output = ''
    logger.info("Dry-running `#{args.shelljoin}`...")
  end
  output
end

#loggerObject



43
44
45
# File 'lib/prlbackup.rb', line 43

def logger
  @logger ||= create_logger
end

#run(*args) ⇒ String

Run the command until it is finished.

Returns:

  • (String)

    stdout of the comand.



32
33
34
35
36
37
38
39
40
41
# File 'lib/prlbackup.rb', line 32

def run(*args)
  logger.info("Running `#{args.shelljoin}`...") if PrlBackup.config[:verbose]
  output = `#{args.shelljoin} 2>&1`
  status = $?
  unless status.success?
    logger.error("Command `#{args.shelljoin}` failed with exit status #{status.exitstatus}:\n#{output}")
    exit(1)
  end
  output
end