Created
January 22, 2013 14:07
-
-
Save robink/4594889 to your computer and use it in GitHub Desktop.
Revisions
-
Robin Komiwes created this gist
Jan 22, 2013 .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,33 @@ module DbBackup @queue = :db_backup def perform( forced_filename = nil ) config = Rails.configuration.database_configuration database = config[Rails.env]["database"] username = config[Rails.env]["username"] password = config[Rails.env]["password"] dumps_path = Rails.root.join('tmp', 'dumps').to_s dump_filename = forced_filename || Socket.gethostname.to_s + "-" + Rails.env + "-" + Time.now.strftime("%Y-%m-%d--%H-%M") + ".sql" dump_path = Rails.root.join('tmp', 'dumps', dump_filename ) Utils.run 'mkdir -p ' + dumps_path Utils.run "mysqldump -u\"#{username}\" -p\"#{password}\" #{database} -r #{dump_path}" cloudfile = CloudfilesConnect.cloudfile container_name = "db_dumps" if !cloudfile.container_exists? container_name CloudfilesConnect.cloudfile.create_container( container_name ) end container = CloudfilesConnect::cloudfile.container( container_name ) o = container.create_object( dump_filename ) o.write( File.open( dump_path ) ) File.delete( dump_path ) end extend self end 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,4 @@ db_backup: cron: "0 */24 * * *" class: DbBackup description: "Backup the Database each day"