Permalink
Browse files

Merge branch 'dumpers'

  • Loading branch information...
2 parents 9b92443 + e5937de commit 57567664f1a79d635c9abba7d7fea2ba7f030457 @everzet committed Jun 11, 2010
Showing with 36 additions and 14 deletions.
  1. +36 −14 lib/capifony.rb
View
@@ -201,10 +201,10 @@ def load_database_config(data, env = 'prod')
end
namespace :database do
- namespace :move do
- desc "Dump remote database, download it to local & populate here"
- task :to_local do
- filename = "#{application}.local_dump.#{Time.now.to_i}.sql.bz2"
+ namespace :dump do
+ desc "Dump remote database"
+ task :remote do
+ filename = "#{application}.remote_dump.#{Time.now.to_i}.sql.bz2"
file = "/tmp/#{filename}"
sqlfile = "#{application}_dump.sql"
config = ""
@@ -226,9 +226,37 @@ def load_database_config(data, env = 'prod')
`mkdir -p backups`
get file, "backups/#{filename}"
+ `cd backups && ln -nfs #{filename} #{application}.remote_dump.latest.sql.bz2`
run "rm #{file}"
+ end
- config = load_database_config IO.read('config/databases.yml'), 'dev'
+ desc "Dump local database"
+ task :local do
+ filename = "#{application}.local_dump.#{Time.now.to_i}.sql.bz2"
+ file = "backups/#{filename}"
+ config = load_database_config IO.read('config/databases.yml'), 'dev'
+ sqlfile = "#{application}_dump.sql"
+
+ `mkdir -p backups`
+ case config['type']
+ when 'mysql'
+ `mysqldump -u#{config['user']} --password='#{config['pass']}' #{config['db']} | bzip2 -c > #{file}`
+ when 'pgsql'
+ `pg_dump -U #{config['user']} --password='#{config['pass']}' #{config['db']} | bzip2 -c > #{file}`
+ end
+
+ `cd backups && ln -nfs #{filename} #{application}.local_dump.latest.sql.bz2`
+ end
+ end
+
+ namespace :move do
+ desc "Dump remote database, download it to local & populate here"
+ task :to_local do
+ filename = "#{application}.remote_dump.latest.sql.bz2"
+ config = load_database_config IO.read('config/databases.yml'), 'dev'
+ sqlfile = "#{application}_dump.sql"
+
+ database.dump.remote
`bunzip2 -kc backups/#{filename} > backups/#{sqlfile}`
case config['type']
@@ -242,18 +270,12 @@ def load_database_config(data, env = 'prod')
desc "Dump local database, load it to remote & populate there"
task :to_remote do
- filename = "#{application}.local_dump.#{Time.now.to_i}.sql.bz2"
+ filename = "#{application}.local_dump.latest.sql.bz2"
file = "backups/#{filename}"
- config = load_database_config IO.read('config/databases.yml'), 'dev'
sqlfile = "#{application}_dump.sql"
+ config = ""
- `mkdir -p backups`
- case config['type']
- when 'mysql'
- `mysqldump -u#{config['user']} --password='#{config['pass']}' #{config['db']} | bzip2 -c > #{file}`
- when 'pgsql'
- `pg_dump -U #{config['user']} --password='#{config['pass']}' #{config['db']} | bzip2 -c > #{file}`
- end
+ database.dump.local
upload(file, "/tmp/#{filename}", :via => :scp)
run "bunzip2 -kc /tmp/#{filename} > /tmp/#{sqlfile}"

0 comments on commit 5756766

Please sign in to comment.