Created
November 1, 2013 21:04
-
-
Save krisalyssa/7271927 to your computer and use it in GitHub Desktop.
Usage: pg_copy (source database name) (destination database name)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -wKU | |
(@from_spec, @to_spec) = ARGV | |
if @from_spec.match(/^([^:]+):(.+)$/) { | md | @from_server = md[1]; @from_db = md[2] } | |
@from = "ssh #{@from_server} 'pg_dump -Fc -c -O -v -- #{@from_db}'" | |
else | |
@from = "pg_dump -Fc -c -O -v -- #{@from_spec}" | |
end | |
if @to_spec.match(/^([^:]+):(.+)$/) { | md | @to_server = md[1]; @to_db = md[2] } | |
@to = "ssh #{@to_server} 'pg_restore -Fc -c -O -v -d #{@to_db}'" | |
else | |
@to = "pg_restore -Fc -c -O -v -d #{@to_spec}" | |
end | |
puts "#{@from} | #{@to}" | |
system "#{@from} | #{@to}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment