Skip to content

Instantly share code, notes, and snippets.

@tripolitrax
Created July 21, 2015 09:03
Show Gist options
  • Save tripolitrax/34fc3fae4e7821f8e465 to your computer and use it in GitHub Desktop.
Save tripolitrax/34fc3fae4e7821f8e465 to your computer and use it in GitHub Desktop.
def DB02
if #{$db02DestDir} == nil
puts "Not running synchronization for DB02 as no hostname specified"
abort
else
puts 'Running a complete rsync mirror, please be patient...'.yellow
FileUtils.mkdir_p($db02DestDir) unless File.exists?($db02DestDir)
cmd = `rsync -aHAXxv --numeric-ids --delete --progress -e "ssh -T -c arcfour -o Compression=no -x" #{$username}@#{$db02Host}:#{$db02BackupDir} #{$db02DestDir}`
DB02Log.log.debug "#{cmd}"
puts "#{cmd}"
end
if $?.exitstatus == 0
puts 'Syncing complete!'.green
send_email( "Backup complete: #{Socket.gethostname}", "Complete - Output: #{cmd} \n To validate the backup, please refer to the logfile: #{$db02LogFile}" )
elsif $?.exitstatus == 1
puts "Rsync Error!" .red
send_email( "Backup failure: #{Socket.gethostname}", "Failure - Rsync Error - Please do a manual backup to identify fault. \n To validate the log file, please refer to: #{$db02LogFile}" )
elsif $?.exitstatus == 23
puts "Socket Error!" .red
send_email( "Backup failure: #{Socket.gethostname}", "Failure - Socket Error: Running a rsync backup from #{$hostname} - Check permissions on remote server? \n To validate the log file, please refer to: #{$db02LogFile}" )
else
puts "Unknown error!" .red
send_email( "Backup failure: #{Socket.gethostname}", "Failure - Unknown error - Please troubleshoot for host: #{$hostname} \n please refer to: #{$db02LogFile}" )
end
end
DB02()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment