lib/understudy/cli.rb in understudy-0.0.10 vs lib/understudy/cli.rb in understudy-0.0.11

- old
+ new

@@ -11,11 +11,14 @@ def perform(job) ENV['PATH'] += ":/etc/understudy" ENV['TMPDIR']='/tmp/understudy/' log = Logger.new(STDOUT) - log.level = Logger::INFO if options[:verbose] + log.level = options[:verbose] ? Logger::DEBUG : Logger::INFO + log.formatter = proc do |severity, datetime, progname, msg| + "#{msg}\n" + end job_name = job config_file = "/etc/understudy/#{job_name}.conf" @@ -61,12 +64,14 @@ rdiff_data = "#{config.dest}/rdiff-backup-data" exists = File.directory? rdiff_data if exists && options["first-time"] log.error "Cannot force first time, destination '#{config.dest}' already exists" + return 1 elsif !exists && !options["first-time"] log.error "Destination '#{config.dest}' does not appear to exist, try again with --first-time" + return 1 end run config.command if config.command command = [] @@ -82,23 +87,27 @@ run command, log end private def run(command, log) + backup = RdiffSimple::RdiffBackup.new friendly = nil + succes = false if command.is_a? Array friendly = command.map { |i| i =~ /[^-=\/\.\w]/ ? "#{i}" : i }.join ' ' - log.info "Running: #{friendly}" - RdiffSimple::RdiffBackup.execute( friendly ) or log.error "Could not run #{friendly}" + log.debug "Running: #{friendly}" + success = backup.execute friendly else friendly = command - log.info "Running: #{friendly}" - RdiffSimple::RdiffBackup.execute( friendly ) or log.error "Could not run #{friendly}" + log.debug "Running: #{friendly}" + success = backup.execute friendly end - if $? != 0 - log.error "Could not run #{friendly}" + + log.info backup.output_log + if success + log.debug "Backup successful" else - log.info "Backup successful" + log.error "Could not run #{friendly}" end end end end