Skip to content

Instantly share code, notes, and snippets.

@cpetersen
Created August 14, 2009 03:23
Show Gist options
  • Save cpetersen/167623 to your computer and use it in GitHub Desktop.
Save cpetersen/167623 to your computer and use it in GitHub Desktop.
desc 'backup the production database'
task :backup do
server = "your server"
username = "your user"
keypair = "#{Merb.root}/path/to/your/keypair"
databases = ["your", "databases", "here" ]
ssh_command = "ssh -i #{keypair} -L 5985:localhost:5984 #{username}@#{server}"
pid, stdin, stdout, stderr = Open4::popen4 ssh_command
sleep(2) # Hack to let the connection finish setting up
databases.each do |db|
puts "Replicating #{db}"
`curl -s -X POST -d '{"source":"http://127.0.0.1:5985/depot-#{db}","target":"production-#{db}"}' http://localhost:5984/_replicate`
end
`kill #{pid}`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment