Created
February 28, 2011 09:52
-
-
Save matthijsgroen/847141 to your computer and use it in GitHub Desktop.
Set up database backup scripts
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/ruby | |
u = "root" | |
p = "password" | |
Dir.chdir "/root/database_backups" | |
`git reset --hard` | |
`git checkout backups` | |
`git merge master` | |
database_list = `echo "SHOW DATABASES;" | mysql -u #{u} -p#{p}`.split("\n") | |
database_list.shift # strip the header | |
exclude_list = ["mysql", "information_schema"] | |
backup_list = database_list - exclude_list | |
puts "creating #{backup_list.length} backups:" | |
backup_list.each_with_index do |database, index| | |
puts "#{index + 1}. #{database}" | |
`/usr/local/mysql/bin/mysqldump #{database} -u #{u} -p#{p} > #{database}.sql` | |
`git add #{database}.sql` | |
end | |
puts "committing changes" | |
time_stamp = Time.now.strftime("%Y-%m-%d"); | |
`git commit -a -m "database backups of #{time_stamp}"` | |
`git tag -f "#{time_stamp}"` | |
`git gc --auto` |
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
#!/bin/bash | |
git-init | |
git add exporter.rb setup-git.sh | |
git commit -a -m "setup backup tools" | |
git checkout -b backups | |
ruby exporter.rb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment