Class: Backup::CLI::Utility

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/backup/cli/utility.rb

Instance Method Summary collapse

Instance Method Details

#decryptObject

Decrypt

Shorthand for decrypting encrypted files



165
# File 'lib/backup/cli/utility.rb', line 165

desc 'decrypt', 'Decrypts encrypted files'

#dependenciesObject

Dependencies

Returns a list of Backup’s dependencies



190
# File 'lib/backup/cli/utility.rb', line 190

desc 'dependencies', 'Display the list of dependencies for Backup, or install them through Backup.'

#performObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/backup/cli/utility.rb', line 31

def perform
  ##
  # Silence Backup::Logger from printing to STDOUT, if --quiet was specified
  Logger.quiet = options[:quiet]

  ##
  # Update Config variables based on the given options
  Config.update(options)

  ##
  # Load the configuration file
  Config.load_config!

  ##
  # Ensure the :log_path, :cache_path and :tmp_path are created
  # if they do not yet exist
  [Config.log_path, Config.cache_path, Config.tmp_path].each do |path|
    FileUtils.mkdir_p(path)
  end

  ##
  # Truncate log file if needed
  Logger.truncate!

  ##
  # Prepare all trigger names by splitting them by ','
  # and finding trigger names matching wildcard
  triggers = options[:trigger].split(",")
  triggers.map!(&:strip).map! {|t|
    t.include?('*') ? Model.find_matching(t) : t
  }.flatten!

  ##
  # Process each trigger
  triggers.each do |trigger|
    ##
    # Find the model for this trigger
    # Will raise an error if not found
    model = Model.find(trigger)

    ##
    # Prepare and Perform the backup
    model.prepare!
    model.perform!

    ##
    # Clear the Log Messages for the next potential run
    Logger.clear!
  end

rescue => err
  Logger.error Errors::CLIError.wrap(err)
  exit(1)
end

#triggerObject

Perform

Performs the backup process. The only required option is the –trigger [-t]. If the other options (–config-file, –data-path, –cache–path, –tmp-path) aren’t specified they will fallback to the (good) defaults

If –root-path is given, it will be used as the base path for our defaults, as well as the base path for any option specified as a relative path. Any option given as an absolute path will be used “as-is”.



19
# File 'lib/backup/cli/utility.rb', line 19

method_option :trigger,         :type => :string,  :required => true, :aliases => ['-t', '--triggers']

#versionObject



230
231
232
# File 'lib/backup/cli/utility.rb', line 230

def version
  puts "Backup #{Backup::Version.current}"
end