Skip to content

Instantly share code, notes, and snippets.

@AJ-Acevedo
Created February 27, 2013 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AJ-Acevedo/5051641 to your computer and use it in GitHub Desktop.
Save AJ-Acevedo/5051641 to your computer and use it in GitHub Desktop.
MySQL Database Backup Script
#!/usr/bin/env ruby
# AJ Acevedo | ajacevedo.com
# This script will backup and compress a MySQL database using mysqldump and gzip
# Simply specify the database name, username, and password at the command-line when excucuting the script.
# Usage Syntax:
# $ db_backup.rb database_name username password
database = ARGV.shift
username = ARGV.shift
password = ARGV.shift
end_of_iter = ARGV.shift
if end_of_iter.nil?
backup_file = database + Time.now.strftime("%Y%m%d")
else
backup_file = database + end_of_iter
end
`mysqldump -u#{username} -p#{password} #{database} > #{backup_file}.sql`
`gzip #{backup_file}.sql`
puts 'Backup Complete!'
puts "#{backup_file}.sql.gz saved"
puts 'Type the following to remvove the MySQL user name and password from the bash_history'
puts '$ history -d 2'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment