Created
February 27, 2013 20:56
-
-
Save AJ-Acevedo/5051641 to your computer and use it in GitHub Desktop.
MySQL Database Backup Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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