Class: ChefBackup::Runner
- Inherits:
-
Object
- Object
- ChefBackup::Runner
- Includes:
- Exceptions, Helpers
- Defined in:
- lib/chef_backup/runner.rb
Overview
ChefBackup::Runner class initializes the strategy and runs the action
Constant Summary
Constants included from Helpers
Helpers::DEFAULT_PG_OPTIONS, Helpers::SERVER_ADD_ONS
Instance Method Summary collapse
-
#backup ⇒ TrueClass, FalseClass
Execute Chef Server backup.
-
#backup_name ⇒ String
The backup name from the restore param.
-
#backup_strategy ⇒ String
String name of the configured backup strategy.
- #config ⇒ ChefBackup::Config
-
#ebs_snapshot? ⇒ TrueClass, FalseClass
Is the restore_param an EBS Snapshot ID?.
- #initialize(running_config) ⇒ ChefBackup::Runner constructor
-
#manifest ⇒ Hash
A parsed copy of the manifest.json in the backup tarball.
-
#restore ⇒ TrueClass, FalseClass
Execute Chef Server restore.
-
#restore_directory ⇒ String
Sets the restore_dir in ChefBackup::Config and ensures the directory exists and is cleaned.
-
#restore_param ⇒ String
String of the restore parameter.
-
#restore_strategy ⇒ String
A path to backup tarball or EBS snapshot ID.
-
#tarball? ⇒ TrueClass, FalseClass
Is the restore_param is a tarball?.
-
#unpack_tarball ⇒ TrueClass, FalseClass
Expands tarball into restore directory.
Methods included from Helpers
#addon_install_dir, #all_services, #backend?, #base_config_dir, #base_install_dir, #chpst, #cleanup, #config_base, #ctl_command, #database_name, #disabled_services, #enabled_addons, #enabled_services, #ensure_file!, #frontend?, #ha?, #log, #marketplace?, #online?, #pg_options, #pgsql, #project_name, #reconfigure_add_ons, #reconfigure_marketplace, #restart_add_ons, #restart_chef_server, #running_filepath, #service_config, #service_enabled?, #shell_out, #shell_out!, #shell_timeout, #standalone?, #start_chef_server, #start_service, #stop_chef_server, #stop_service, #strategy, #tier?, #tmp_dir, #topology, #version_from_manifest_file
Constructor Details
#initialize(running_config) ⇒ ChefBackup::Runner
16 17 18 19 |
# File 'lib/chef_backup/runner.rb', line 16 def initialize(running_config) ChefBackup::Config.config = running_config ChefBackup::Logger.logger(service_config["backup"]["logfile"] || nil) end |
Instance Method Details
#backup ⇒ TrueClass, FalseClass
Returns Execute Chef Server backup.
24 25 26 27 |
# File 'lib/chef_backup/runner.rb', line 24 def backup @backup ||= ChefBackup::Strategy.backup(backup_strategy) @backup.backup end |
#backup_name ⇒ String
Returns The backup name from the restore param.
101 102 103 104 105 106 107 |
# File 'lib/chef_backup/runner.rb', line 101 def backup_name if tarball? Pathname.new(restore_param).basename.sub_ext("").to_s elsif ebs_snapshot? restore_param end end |
#backup_strategy ⇒ String
Returns String name of the configured backup strategy.
47 48 49 |
# File 'lib/chef_backup/runner.rb', line 47 def backup_strategy service_config["backup"]["strategy"] end |
#config ⇒ ChefBackup::Config
32 33 34 |
# File 'lib/chef_backup/runner.rb', line 32 def config ChefBackup::Config.config end |
#ebs_snapshot? ⇒ TrueClass, FalseClass
Returns Is the restore_param an EBS Snapshot ID?.
84 85 86 |
# File 'lib/chef_backup/runner.rb', line 84 def ebs_snapshot? restore_param =~ /^snap-\h{8}$/ end |
#manifest ⇒ Hash
Returns A parsed copy of the manifest.json in the backup tarball.
131 132 133 134 135 136 137 |
# File 'lib/chef_backup/runner.rb', line 131 def manifest @manifest ||= begin file = "#{restore_directory}/manifest.json" ensure_file!(file, InvalidTarball, "No manifest found in tarball") JSON.parse(File.read(file)) end end |
#restore ⇒ TrueClass, FalseClass
Returns Execute Chef Server restore.
39 40 41 42 |
# File 'lib/chef_backup/runner.rb', line 39 def restore @restore ||= ChefBackup::Strategy.restore(restore_strategy, restore_param) @restore.restore end |
#restore_directory ⇒ String
Sets the restore_dir in ChefBackup::Config and ensures the directory exists and is cleaned.
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/chef_backup/runner.rb', line 115 def restore_directory config["restore_dir"] ||= begin dir_name = File.join(tmp_dir, backup_name) if File.directory?(dir_name) # clean restore directory if it exists FileUtils.rm_r(Dir.glob("#{dir_name}/*")) else FileUtils.mkdir_p(dir_name) end dir_name end end |
#restore_param ⇒ String
Returns String of the restore parameter. eg: EBS snapshot ID or a path to a tarball.
55 56 57 |
# File 'lib/chef_backup/runner.rb', line 55 def restore_param config["restore_param"] end |
#restore_strategy ⇒ String
Returns A path to backup tarball or EBS snapshot ID.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/chef_backup/runner.rb', line 62 def restore_strategy @restore_strategy ||= if tarball? unpack_tarball manifest["strategy"] elsif ebs_snapshot? "ebs" else raise InvalidStrategy, "#{restore_param} is not a valid backup" end end |
#tarball? ⇒ TrueClass, FalseClass
Returns Is the restore_param is a tarball?.
76 77 78 79 |
# File 'lib/chef_backup/runner.rb', line 76 def tarball? file = Pathname.new(File.(restore_param)) file.exist? && file.extname == ".tgz" end |
#unpack_tarball ⇒ TrueClass, FalseClass
Returns Expands tarball into restore directory.
91 92 93 94 95 96 |
# File 'lib/chef_backup/runner.rb', line 91 def unpack_tarball file = File.(restore_param) ensure_file!(file, InvalidTarball, "#{file} not found") log "Expanding tarball: #{file}" shell_out!("tar zxf #{file} -C #{restore_directory}") end |