Skip to content

Commit 1820ad8

Browse files
committed
feat: Add backup task for backing up the remote database.
1 parent 52f5772 commit 1820ad8

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ assets:remote:sync || assets:push # Synchronize your remote assets using local
7676
7777
db:local:sync || db:pull # Synchronize your local database using remote database data
7878
db:remote:sync || db:push # Synchronize your remote database using local database data
79+
db:remote:backup || db:backup # Backup the remote database and download it
7980
```
8081

8182
## Example

lib/capistrano-db-tasks/database.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def postgresql_db_valid?(local_db, remote_db)
215215
(remote_db.nil? || (remote_db && remote_db.postgresql?))
216216
end
217217

218-
def remote_to_local(instance)
218+
def remote_to_local(instance, sync=true)
219219
local_db = Database::Local.new(instance)
220220
remote_db = Database::Remote.new(instance)
221221

@@ -226,7 +226,7 @@ def remote_to_local(instance)
226226
ensure
227227
remote_db.clean_dump_if_needed
228228
end
229-
local_db.load(remote_db.output_file, instance.fetch(:db_local_clean))
229+
local_db.load(remote_db.output_file, instance.fetch(:db_local_clean)) if sync
230230
end
231231

232232
def local_to_remote(instance)

lib/capistrano-db-tasks/dbtasks.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@
3131
end
3232
end
3333
end
34+
35+
desc 'Backup the remote database data and download it'
36+
task :backup do
37+
on roles(:db) do
38+
if fetch(:skip_data_sync_confirm) || Util.prompt('Are you sure you want to erase your local database with server database')
39+
puts "Downloading your backup file for remote database..."
40+
Database.remote_to_local(self, false)
41+
end
42+
end
43+
end
3444
end
3545

3646
namespace :local do
@@ -66,6 +76,9 @@
6676
end
6777
end
6878

79+
desc 'Backup the remote database and download it'
80+
task :backup => "db:remote:backup"
81+
6982
desc 'Synchronize your local database using remote database data'
7083
task :pull => "db:local:sync"
7184

0 commit comments

Comments
 (0)