From 0c7d3ffebe1fa384f19d9938b6b3f90f96801b1e Mon Sep 17 00:00:00 2001 From: lanzhiheng Date: Sun, 26 Jul 2020 18:47:39 +0800 Subject: [PATCH] feat: Add backup task for backing up the remote database. --- README.md | 1 + capistrano-db-tasks.gemspec | 2 -- lib/capistrano-db-tasks/database.rb | 4 ++-- lib/capistrano-db-tasks/dbtasks.rb | 13 +++++++++++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c60b783..ef033c1 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ assets:remote:sync || assets:push # Synchronize your remote assets using local 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 || db:backup # Backup the remote database and download it ``` ## Example diff --git a/capistrano-db-tasks.gemspec b/capistrano-db-tasks.gemspec index 802b846..46b8af6 100644 --- a/capistrano-db-tasks.gemspec +++ b/capistrano-db-tasks.gemspec @@ -12,8 +12,6 @@ Gem::Specification.new do |gem| gem.summary = "A collection of capistrano tasks for syncing assets and databases" gem.description = "A collection of capistrano tasks for syncing assets and databases" - gem.rubyforge_project = "capistrano-db-tasks" - gem.licenses = ["MIT"] gem.files = `git ls-files`.split("\n") diff --git a/lib/capistrano-db-tasks/database.rb b/lib/capistrano-db-tasks/database.rb index 8bbeabe..dd64e44 100644 --- a/lib/capistrano-db-tasks/database.rb +++ b/lib/capistrano-db-tasks/database.rb @@ -215,7 +215,7 @@ def postgresql_db_valid?(local_db, remote_db) (remote_db.nil? || (remote_db && remote_db.postgresql?)) end - def remote_to_local(instance) + def remote_to_local(instance, sync=true) local_db = Database::Local.new(instance) remote_db = Database::Remote.new(instance) @@ -226,7 +226,7 @@ def remote_to_local(instance) ensure remote_db.clean_dump_if_needed end - local_db.load(remote_db.output_file, instance.fetch(:db_local_clean)) + local_db.load(remote_db.output_file, instance.fetch(:db_local_clean)) if sync end def local_to_remote(instance) diff --git a/lib/capistrano-db-tasks/dbtasks.rb b/lib/capistrano-db-tasks/dbtasks.rb index 15891be..185f2d1 100644 --- a/lib/capistrano-db-tasks/dbtasks.rb +++ b/lib/capistrano-db-tasks/dbtasks.rb @@ -31,6 +31,16 @@ end end end + + desc 'Backup the remote database data and download it' + task :backup do + on roles(:db) do + if fetch(:skip_data_sync_confirm) || Util.prompt('Are you sure you want to erase your local database with server database') + puts "Downloading your backup file for remote database..." + Database.remote_to_local(self, false) + end + end + end end namespace :local do @@ -66,6 +76,9 @@ end end + desc 'Backup the remote database and download it' + task :backup => "db:remote:backup" + desc 'Synchronize your local database using remote database data' task :pull => "db:local:sync"