heroku-db-sync 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  Adds rake tasks to perform backup and restore between heroku remotes
4
4
 
5
+ Recommended git remotes setup pattern:
6
+
7
+ $ git remote -v
8
+ origin git@github.com:rubynor/somecoolproject.git (fetch)
9
+ origin git@github.com:rubynor/somecoolproject.git (push)
10
+ production git@heroku.com:somecoolproject.git (fetch)
11
+ production git@heroku.com:somecoolproject.git (push)
12
+ staging git@heroku.com:somecoolproject-stage.git (fetch)
13
+ staging git@heroku.com:somecoolproject-stage.git (push)
14
+
5
15
  ## Usage
6
16
 
7
17
  gem 'heroku-db-sync'
@@ -11,11 +21,15 @@ Adds rake tasks to perform backup and restore between heroku remotes
11
21
 
12
22
  #backup production and overwrite staging db
13
23
  rake db:sync:heroku:staging
24
+
25
+ #NOTE: heroku will prompt you to confirm the name of the before overwriting it! Remember to type it
14
26
 
15
27
  you may also specify remotes
16
28
 
17
29
  rake db:sync:heroku:remote[staging,production]
18
- #where to_remote:staging and from_remote:production
30
+ #where to_remote=staging and from_remote=production
31
+ rake db:sync:heroku:local[staging]
32
+ #where from_remote=staging
19
33
 
20
34
  ## Contributing
21
35
 
@@ -2,40 +2,42 @@
2
2
  module HerokuDbSync
3
3
  module TaskHelper
4
4
  def self.perform_sync arguments
5
- @arguments = arguments
6
- from_remote = arguments[:from_remote] || 'production'
7
- to_remote = arguments[:to_remote]
5
+ Bundler.with_clean_env do
6
+ @arguments = arguments
7
+ from_remote = arguments[:from_remote] || 'production'
8
+ to_remote = arguments[:to_remote]
8
9
 
9
- puts "(1/4) capturing #{from_remote} database snapshot..."
10
- run "heroku pgbackups:capture --expire --remote #{from_remote}"
10
+ puts "(1/4) capturing #{from_remote} database snapshot..."
11
+ run "heroku pgbackups:capture --expire --remote #{from_remote}"
11
12
 
12
- if to_remote
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 .."
18
- restore_cmd = "heroku pgbackups:restore DATABASE '#{backup_url}' --remote #{to_remote}"
19
- puts restore_cmd
20
- run restore_cmd # use 'system' as heroku prompts for confirmation of db restore.
21
- puts "(4/4) restarting remote #{to_remote}"
22
- run "heroku restart --remote #{to_remote}"
23
- else
24
- dumpfile = 'latest.dump'
25
- puts "(2/4) downloading snapshot..."
26
- run "curl -o #{dumpfile} \`heroku pgbackups:url --remote #{from_remote}\`"
27
- puts "(3/4) restoring snapshot to #{host} database #{database} ... "
28
- `pg_restore --verbose --clean --no-acl --no-owner -h #{host} -U #{user} -d #{database} #{dumpfile}`
29
- keep = arguments[:keepdump] || false
30
- unless keep
31
- puts "(4/4) cleaning up..."
32
- `rm #{dumpfile}`
13
+ if to_remote
14
+ puts "(2/4) fetching backup url from remote #{from_remote}"
15
+ backup_url = runr("heroku pgbackups:url --remote #{from_remote}")
16
+ print "(3/4) backing up #{to_remote} and restoring it from snapshot from #{from_remote} ... "
17
+ run "heroku pgbackups:capture --expire --remote #{to_remote}"
18
+ puts "captured. restoring .."
19
+ restore_cmd = "heroku pgbackups:restore DATABASE '#{backup_url}' --remote #{to_remote}"
20
+ puts restore_cmd
21
+ run restore_cmd # use 'system' as heroku prompts for confirmation of db restore.
22
+ puts "(4/4) restarting remote #{to_remote}"
23
+ run "heroku restart --remote #{to_remote}"
33
24
  else
34
- puts "(4/4) keeping #{dumpfile}"
25
+ dumpfile = 'latest.dump'
26
+ puts "(2/4) downloading snapshot..."
27
+ run "curl -o #{dumpfile} \`heroku pgbackups:url --remote #{from_remote}\`"
28
+ puts "(3/4) restoring snapshot to #{host} database #{database} ... "
29
+ `pg_restore --verbose --clean --no-acl --no-owner -h #{host} -U #{user} -d #{database} #{dumpfile}`
30
+ keep = arguments[:keepdump] || false
31
+ unless keep
32
+ puts "(4/4) cleaning up..."
33
+ `rm #{dumpfile}`
34
+ else
35
+ puts "(4/4) keeping #{dumpfile}"
36
+ end
35
37
  end
36
- end
37
38
 
38
- puts "Success! Ah, that was exhausting, pop a beer!"
39
+ puts "Success! Ah, that was exhausting, pop a beer!"
40
+ end
39
41
  end
40
42
 
41
43
  def self.host
@@ -1,3 +1,3 @@
1
1
  module HerokuDbSync
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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.2
4
+ version: 0.1.3
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-16 00:00:00.000000000 Z
12
+ date: 2013-12-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -27,22 +27,6 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: heroku
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :runtime
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
30
  - !ruby/object:Gem::Dependency
47
31
  name: sqlite3
48
32
  requirement: !ruby/object:Gem::Requirement