Skip to content

Instantly share code, notes, and snippets.

@derencius
Created September 13, 2021 15:29
Show Gist options
  • Save derencius/a4eeb4ddee74f4e5e180cc91ecd79973 to your computer and use it in GitHub Desktop.
Save derencius/a4eeb4ddee74f4e5e180cc91ecd79973 to your computer and use it in GitHub Desktop.
DB - postgres restore
#!/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