Last active
August 6, 2021 13:36
-
-
Save ahmadhasankhan/fb7b004a6e171215bb9e to your computer and use it in GitHub Desktop.
Revisions
-
ahmadhasankhan revised this gist
May 15, 2015 . 1 changed file with 28 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ #1===========First code================ #!/usr/bin/env ruby databases = { @@ -30,3 +32,29 @@ `gzip #{backup_file}.sql` end #2===========Taking database info from the command line instead of an internal Hash================ #!/usr/bin/env ruby database = ARGV.shift username = ARGV.shift password = ARGV.shift host = 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 = "mysqldump -h#{host} -u#{username} -p#{password} #{database}" `#{mysqldump} > #{backup_file}.sql` `gzip #{backup_file}.sql` # To perform our backup, we call it like so: db_backup.rb db_name username password host_name -
ahmadhasankhan created this gist
May 15, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ #!/usr/bin/env ruby databases = { :local_db => { :database => 'my_db', :username => 'root', :password => 'admin', :host => 'localhost' }, :staging_db => { :database => 'db_name', :username => 'db_user', :password => 'p@ssWord!', :host => 'localhost' } } end_of_iter = ARGV.shift databases.each do |name, config| if end_of_iter.nil? backup_file = config[:database] + '_' + Time.now.strftime('%Y%m%d') else backup_file = config[:database] + '_' + end_of_iter end mysqldump = "mysqldump -h#{config[:host]} -u#{config[:username]} -p#{config[:password]} #{config[:database]}" `#{mysqldump} > #{backup_file}.sql` `gzip #{backup_file}.sql` end