Skip to content

Instantly share code, notes, and snippets.

@matthijsgroen
Created February 28, 2011 09:52
Show Gist options
  • Save matthijsgroen/847141 to your computer and use it in GitHub Desktop.
Save matthijsgroen/847141 to your computer and use it in GitHub Desktop.
Set up database backup scripts
#!/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`
#!/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