Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 0) Setup
- $DATE_FORMAT = "%Y%m%d"
- $BACKUP_FILENAME = "mysecret-database-daily-#{Time.now.strftime($DATE_FORMAT)}.sql.gz"
- $BACKUP_LOCATION = "/mnt/backups/"
- $USERNAME = "ninja"
- $PASSWORD = "pirate"
- $DATABASE = "japanese_boat"
- $MAIL_FROM = "aaarrrgh@brightlight-ict.nl"
- $MAIL_TO = "maran@brightlight-ict.nl"
- mailer = SimpleMailer.new($MAIL_FROM, $MAIL_TO)
- # 1) Get backup from somewhere
- unless system("cp #{$BACKUP_LOCATION}#{$BACKUP_FILENAME} ./ ")
- mailer.sad_mail "Something went wrong while copying the backup, exiting..."
- exit
- end
- # 2) Dump old tables
- unless system("mysql --silent --skip-column-names -u #{$USERNAME} --password=\"#{$PASSWORD}\" #{$DATABASE} -e \"show tables\" | gawk '{print \"drop table \" $1 \";\"}' | mysql -u #{$USERNAME} --password=\"#{$PASSWORD}\" #{$DATABASE}")
- mailer.sad_mail "Couldn't drop tables, exitings.."
- exit
- end
- # 3) Import new database
- unless system("zcat #{$BACKUP_FILENAME} | mysql -u #{$USERNAME} --password=#{$PASSWORD} #{$DATABASE}")
- mailer.sad_mail "Couldn't import tables, exiting.."
- exit
- end
- # 4) Everything went a-ok!
- mailer.happy_mail
Add Comment
Please, Sign In to add comment