class Backupsss::Runner
A Class for running this backup utility
Attributes
config[RW]
Public Class Methods
new()
click to toggle source
# File lib/backupsss.rb, line 17 def initialize @config = Backupsss::Configuration.new end
Public Instance Methods
run()
click to toggle source
# File lib/backupsss.rb, line 21 def run config.backup_freq ? run_scheduled : run_oneshot end
Private Instance Methods
call()
click to toggle source
# File lib/backupsss.rb, line 27 def call push_backup(*prep_for_backup) cleanup_local cleanup_remote end
cleanup_local()
click to toggle source
# File lib/backupsss.rb, line 57 def cleanup_local local_janitor = Janitor.new( driver: BackupDir.new(dir: config.backup_dest_dir) ) local_janitor.rm_garbage(local_janitor.sift_trash) end
cleanup_remote()
click to toggle source
# File lib/backupsss.rb, line 64 def cleanup_remote remote_janitor = Janitor.new( driver: BackupBucket.new( dir: "#{config.s3_bucket}/#{config.s3_bucket_prefix}", region: config.aws_region ), retention_count: config.remote_retention ) remote_janitor.rm_garbage(remote_janitor.sift_trash) end
make_call()
click to toggle source
# File lib/backupsss.rb, line 89 def make_call call rescue => exc error_message = "ERROR - backup failed: #{exc.message}\n#{exc.backtrace.join("\n\t")}" if config.backup_freq $stderr.puts error_message else abort(error_message) end end
prep_for_backup()
click to toggle source
# File lib/backupsss.rb, line 33 def prep_for_backup filename = "#{Time.now.to_i}.tar" backup = Backupsss::Backup.new( { s3_bucket_prefix: config.s3_bucket_prefix, s3_bucket: config.s3_bucket, filename: filename }, Aws::S3::Client.new(region: config.aws_region) ) [filename, backup] end
push_backup(filename, backup)
click to toggle source
# File lib/backupsss.rb, line 46 def push_backup(filename, backup) puts 'Create and Upload Tar: Starting' backup.put_file( Backupsss::Tar.new( config.backup_src_dir, "#{config.backup_dest_dir}/#{filename}" ).make ) puts 'Create and Upload Tar: Finished' end
run_oneshot()
click to toggle source
# File lib/backupsss.rb, line 83 def run_oneshot $stdout.puts 'No Schedule provided, running one time task' make_call end
run_scheduled()
click to toggle source
# File lib/backupsss.rb, line 75 def run_scheduled $stdout.puts "Schedule provided, running with #{config.backup_freq}" scheduler = Rufus::Scheduler.new scheduler.cron(config.backup_freq, blocking: true) { make_call } scheduler.join end