Skip to content

Commit

Permalink
feat: Add backup task for backing up the remote database.
Browse files Browse the repository at this point in the history
  • Loading branch information
lanzhiheng committed Jul 26, 2020
1 parent 52f5772 commit 1820ad8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/capistrano-db-tasks/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions lib/capistrano-db-tasks/dbtasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"

Expand Down

0 comments on commit 1820ad8

Please sign in to comment.