Skip to content

Instantly share code, notes, and snippets.

@handerson
Created February 17, 2012 00:24
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 handerson/1849135 to your computer and use it in GitHub Desktop.
Save handerson/1849135 to your computer and use it in GitHub Desktop.
Creates a MySQL dump and backs it up to Rackspace Cloudfiles and maintains 14 days worth of backups
require 'rubygems'
require 'cloudfiles'
cf = CloudFiles::Connection.new(:username => "", :api_key => "")
`mysqldump -u root --password=password --all-databases > /home/deploy/backup.sql`
file = File.new("/home/deploy/backup.sql")
if file
container = cf.container('backups')
object = container.create_object "servername_backup_#{file.mtime.strftime("%Y-%m-%d")}.sql", false
object.write file
end
file.close
backups = container.objects.select{|o| o =~ /servername.+/}
if backups.length > 14
backups.sort!
container.delete_object(backups.first)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment