Created
September 13, 2021 15:29
-
-
Save derencius/a4eeb4ddee74f4e5e180cc91ecd79973 to your computer and use it in GitHub Desktop.
DB - postgres restore
This file contains 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 | |
require 'thor' | |
class MyCLI < Thor | |
desc 'download', 'production database' | |
def download(remote = 'production') | |
puts "Downloading... #{remote}" | |
system "#{remote} pg:backups:capture" | |
system "curl `#{remote} pg:backups:url` -o #{remote}.dump" | |
puts 'Done!' | |
end | |
desc 'restore', 'load dump in dev database' | |
def restore(remote, db) | |
system "ps ax | grep postgres: | grep #{db} | cut -c1-8 | xargs kill" | |
system "dropdb #{db}; createdb #{db}" | |
system "pg_restore --verbose --clean --no-acl --no-owner -j 6 -d #{db} #{remote}" | |
system 'touch tmp/restart.txt' | |
end | |
desc 'dr', 'load dump in dev database' | |
def dr | |
download('production') | |
restore('production', 'honcho') | |
end | |
end | |
MyCLI.start(ARGV) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment