Created
February 17, 2012 00:24
-
-
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
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
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