diff --git a/README.markdown b/README.markdown index 4e43b13..3508b6b 100644 --- a/README.markdown +++ b/README.markdown @@ -77,6 +77,7 @@ Available tasks db:local:sync || db:pull # Synchronize your local database using remote database data db:remote:sync || db:push # Synchronize your remote database using local database data + db:remote:backup # Dumps database to db folder after that we can take it from there Example ======= diff --git a/lib/capistrano-db-tasks/compressors/bzip2.rb b/lib/capistrano-db-tasks/compressors/bzip2.rb index dd34436..782089e 100644 --- a/lib/capistrano-db-tasks/compressors/bzip2.rb +++ b/lib/capistrano-db-tasks/compressors/bzip2.rb @@ -32,7 +32,7 @@ def decompress(from, to = nil) "-c --stdout > #{to}" end - "bunzip2 -f #{from} #{to}" + "bunzip2 -k -f #{from} #{to}" end end diff --git a/lib/capistrano-db-tasks/database.rb b/lib/capistrano-db-tasks/database.rb index 79f5f10..aecf6ae 100644 --- a/lib/capistrano-db-tasks/database.rb +++ b/lib/capistrano-db-tasks/database.rb @@ -121,6 +121,7 @@ def initialize(cap_instance) def dump @cap.execute "cd #{@cap.current_path} && #{dump_cmd} | #{compressor.compress('-', output_file)}" + @cap.execute("ln -fs #{@cap.current_path}/#{output_file} #{@cap.current_path}/db/latest.sql.#{compressor.file_extension}") self end @@ -229,5 +230,16 @@ def local_to_remote(instance) remote_db.load(local_db.output_file, instance.fetch(:db_local_clean)) File.unlink(local_db.output_file) if instance.fetch(:db_local_clean) end + + def backup(instance) + remote_db = Database::Remote.new(instance) + remote_db.dump + remote_db.download + end + + def restore_latest(instance) + remote_db = Database::Remote.new(instance) + remote_db.load("#{instance.current_path}/db/latest.sql.#{remote_db.compressor.file_extension}", true) + end end end diff --git a/lib/capistrano-db-tasks/dbtasks.rb b/lib/capistrano-db-tasks/dbtasks.rb index 13e01e3..fc6de8e 100644 --- a/lib/capistrano-db-tasks/dbtasks.rb +++ b/lib/capistrano-db-tasks/dbtasks.rb @@ -30,6 +30,20 @@ end end end + + desc 'Dumps database to db folder after that we can take it from there' + task :backup do + on roles(:db) do + Database.backup(self) + end + end + + desc 'Restores the latest database dump from the remote folder (pairs with db:remote:backup)' + task :restore_latest do + on roles(:db) do + Database.restore_latest(self) + end + end end namespace :local do