Skip to content

Commit

Permalink
Add db:remote:restore_latest task
Browse files Browse the repository at this point in the history
  • Loading branch information
cmrd-senya committed Apr 8, 2016
1 parent 1450d5f commit b8beb1c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/capistrano-db-tasks/compressors/bzip2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def decompress(from, to = nil)
"-c --stdout > #{to}"
end

"bunzip2 -f #{from} #{to}"
"bunzip2 -k -f #{from} #{to}"
end

end
Expand Down
6 changes: 6 additions & 0 deletions lib/capistrano-db-tasks/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,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

Expand Down Expand Up @@ -212,6 +213,11 @@ def backup(instance)
remote_db = Database::Remote.new(instance)
remote_db.dump
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
7 changes: 7 additions & 0 deletions lib/capistrano-db-tasks/dbtasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
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
Expand Down

0 comments on commit b8beb1c

Please sign in to comment.