Skip to content

feat: Add backup task for backing up the remote database. #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 0 additions & 2 deletions capistrano-db-tasks.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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")
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