module DatadogBackup::LocalFilesystem
Public Instance Methods
all_file_ids()
click to toggle source
# File lib/datadog_backup/local_filesystem.rb, line 18 def all_file_ids all_files.map { |file| ::File.basename(file, '.*') } end
all_file_ids_for_selected_resources()
click to toggle source
# File lib/datadog_backup/local_filesystem.rb, line 22 def all_file_ids_for_selected_resources all_file_ids.select do |id| resources.include? class_from_id(id) end end
all_files()
click to toggle source
Meant to be mixed into DatadogBackup::Core
Relies on @options and @options
# File lib/datadog_backup/local_filesystem.rb, line 14 def all_files ::Dir.glob(::File.join(backup_dir, '**', '*')).select { |f| ::File.file?(f) } end
class_from_id(id)
click to toggle source
# File lib/datadog_backup/local_filesystem.rb, line 28 def class_from_id(id) class_string = ::File.dirname(find_file_by_id(id)).split('/').last.capitalize ::DatadogBackup.const_get(class_string) end
dump(object)
click to toggle source
# File lib/datadog_backup/local_filesystem.rb, line 33 def dump(object) case output_format when :json JSON.pretty_generate(object.deep_sort) when :yaml YAML.dump(object.deep_sort) else raise 'invalid output_format specified or not specified' end end
file_type(filepath)
click to toggle source
# File lib/datadog_backup/local_filesystem.rb, line 48 def file_type(filepath) ::File.extname(filepath).strip.downcase[1..-1].to_sym end
filename(id)
click to toggle source
# File lib/datadog_backup/local_filesystem.rb, line 44 def filename(id) ::File.join(mydir, "#{id}.#{output_format}") end
find_file_by_id(id)
click to toggle source
# File lib/datadog_backup/local_filesystem.rb, line 52 def find_file_by_id(id) ::Dir.glob(::File.join(backup_dir, '**', "#{id}.*")).first end
load_from_file(string, output_format)
click to toggle source
# File lib/datadog_backup/local_filesystem.rb, line 56 def load_from_file(string, output_format) case output_format when :json JSON.parse(string) when :yaml YAML.safe_load(string) else raise 'invalid output_format specified or not specified' end end
load_from_file_by_id(id)
click to toggle source
# File lib/datadog_backup/local_filesystem.rb, line 67 def load_from_file_by_id(id) filepath = find_file_by_id(id) load_from_file(::File.read(filepath), file_type(filepath)) end
mydir()
click to toggle source
# File lib/datadog_backup/local_filesystem.rb, line 72 def mydir ::File.join(backup_dir, myclass) end
purge()
click to toggle source
# File lib/datadog_backup/local_filesystem.rb, line 76 def purge ::FileUtils.rm(::Dir.glob(File.join(mydir, '*'))) end
write_file(data, filename)
click to toggle source
# File lib/datadog_backup/local_filesystem.rb, line 80 def write_file(data, filename) logger.info "Backing up #{filename}" file = ::File.open(filename, 'w') file.write(data) ensure file.close end