heroku-db-sync 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +31 -0
- data/lib/heroku-db-sync/task_helper.rb +22 -8
- data/lib/heroku-db-sync/version.rb +1 -1
- data/lib/tasks/heroku-db-sync_tasks.rake +2 -2
- metadata +3 -3
- data/README.rdoc +0 -3
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# HerokuDbSync
|
2
|
+
|
3
|
+
Adds rake tasks to perform backup and restore between heroku remotes
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
gem 'heroku-db-sync'
|
8
|
+
|
9
|
+
#backup production and copy to localdevelopment pg db
|
10
|
+
rake db:sync:heroku:local
|
11
|
+
|
12
|
+
#backup production and overwrite staging db
|
13
|
+
rake db:sync:heroku:staging
|
14
|
+
|
15
|
+
you may also specify remotes
|
16
|
+
|
17
|
+
rake db:sync:heroku:remote[staging,production]
|
18
|
+
#where to_remote:staging and from_remote:production
|
19
|
+
|
20
|
+
## Contributing
|
21
|
+
|
22
|
+
1. Fork it
|
23
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
24
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
25
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
26
|
+
5. Create new Pull Request
|
27
|
+
|
28
|
+
|
29
|
+
## License
|
30
|
+
|
31
|
+
This project rocks and uses MIT-LICENSE.
|
@@ -7,22 +7,23 @@ module HerokuDbSync
|
|
7
7
|
to_remote = arguments[:to_remote]
|
8
8
|
|
9
9
|
puts "(1/4) capturing #{from_remote} database snapshot..."
|
10
|
-
|
10
|
+
run "heroku pgbackups:capture --expire --remote #{from_remote}"
|
11
11
|
|
12
12
|
if to_remote
|
13
|
-
puts "2/4 fetching backup url from remote #{from_remote}"
|
14
|
-
backup_url =
|
15
|
-
|
16
|
-
|
13
|
+
puts "(2/4) fetching backup url from remote #{from_remote}"
|
14
|
+
backup_url = runr("heroku pgbackups:url --remote #{from_remote}")
|
15
|
+
print "(3/4) backing up #{to_remote} and restoring it to snapshot from #{from_remote} ... "
|
16
|
+
run "heroku pgbackups:capture --expire --remote #{to_remote}"
|
17
|
+
puts "captured. restoring .."
|
17
18
|
restore_cmd = "heroku pgbackups:restore DATABASE '#{backup_url}' --remote #{to_remote}"
|
18
19
|
puts restore_cmd
|
19
|
-
|
20
|
+
run restore_cmd # use 'system' as heroku prompts for confirmation of db restore.
|
20
21
|
puts "(4/4) restarting remote #{to_remote}"
|
21
|
-
|
22
|
+
run "heroku restart --remote #{to_remote}"
|
22
23
|
else
|
23
24
|
dumpfile = 'latest.dump'
|
24
25
|
puts "(2/4) downloading snapshot..."
|
25
|
-
|
26
|
+
run "curl -o #{dumpfile} \`heroku pgbackups:url --remote #{from_remote}\`"
|
26
27
|
puts "(3/4) restoring snapshot to #{host} database #{database} ... "
|
27
28
|
`pg_restore --verbose --clean --no-acl --no-owner -h #{host} -U #{user} -d #{database} #{dumpfile}`
|
28
29
|
keep = arguments[:keepdump] || false
|
@@ -52,5 +53,18 @@ module HerokuDbSync
|
|
52
53
|
def self.db_config
|
53
54
|
@_db_config ||= Rails.configuration.database_configuration[Rails.env].with_indifferent_access
|
54
55
|
end
|
56
|
+
|
57
|
+
private
|
58
|
+
# Execute commands using system. This command returns true or false if it was a success.
|
59
|
+
# system() also allows prompts to be shown. This is needed for the restore command, heroku asks the user to type the application name
|
60
|
+
def self.run command
|
61
|
+
system(command) || raise("ERROR running < #{command} >. Look above for details")
|
62
|
+
end
|
63
|
+
|
64
|
+
# Execute command using ` `. This returns the result as a string, empty if it failed.
|
65
|
+
def self.runr command
|
66
|
+
res = `#{command}`.strip
|
67
|
+
res.empty? ? raise("ERROR running < #{command} >. Empty result. Look above for details") : res
|
68
|
+
end
|
55
69
|
end
|
56
70
|
end
|
@@ -7,12 +7,12 @@ namespace :db do
|
|
7
7
|
HerokuDbSync::TaskHelper.perform_sync arguments.to_hash.merge({to_remote: nil})
|
8
8
|
end
|
9
9
|
|
10
|
-
desc 'sync heroku DB from
|
10
|
+
desc 'sync staging heroku DB from production heroku DB. default from_remote=production and to_remote=staging'
|
11
11
|
task :staging, [:from_remote] do | task, arguments |
|
12
12
|
HerokuDbSync::TaskHelper.perform_sync arguments.to_hash.merge({to_remote: 'staging'})
|
13
13
|
end
|
14
14
|
|
15
|
-
desc 'sync heroku DB from
|
15
|
+
desc 'sync [to_remote] heroku DB from [from_remote] heroku DB. default from_remote=production and to_remote=staging'
|
16
16
|
task :remote, [:to_remote, :from_remote ] do | task, arguments |
|
17
17
|
raise "must set from_remote ('git remote' for heroku)" unless arguments[:from_remote]
|
18
18
|
raise "must set to_remote ('git remote' for heroku)" unless arguments[:to_remote]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heroku-db-sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -72,7 +72,7 @@ files:
|
|
72
72
|
- lib/tasks/heroku-db-sync_tasks.rake
|
73
73
|
- MIT-LICENSE
|
74
74
|
- Rakefile
|
75
|
-
- README.
|
75
|
+
- README.md
|
76
76
|
- test/dummy/app/assets/javascripts/application.js
|
77
77
|
- test/dummy/app/assets/stylesheets/application.css
|
78
78
|
- test/dummy/app/controllers/application_controller.rb
|
data/README.rdoc
DELETED