Skip to content

Instantly share code, notes, and snippets.

@overture8
Created May 4, 2011 12:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save overture8/955156 to your computer and use it in GitHub Desktop.
Save overture8/955156 to your computer and use it in GitHub Desktop.
Database plugin for the backup gem. Allows remote backups of MySQL databases.
require 'net/ssh'
module Backup
module Database
class SshBackup < Base
attr_accessor :name
attr_accessor :host
attr_accessor :username
attr_accessor :password
attr_accessor :host_username
attr_accessor :host_password
def initialize(&block)
instance_eval(&block)
prepare!
end
def perform!
log!
Net::SSH.start(host, host_username, :password => host_password) do |ssh|
File.open("#{File.join(dump_path, name)}.sql", 'w') do |f|
f.binmode
f << ssh.exec!("mysqldump -u#{username} -p#{password} #{name}")
end
end
end
end
end
end
# Usage
database Backup::Database::SshBackup do |db|
db.name = "dbname"
db.username = "dbuser"
db.password = "dbpassword"
db.host = "hostname"
db.host_username = "hostuser"
db.host_password = "hostpassword"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment