From b5fff02ebdc764821500a136bc838b5cf31513d4 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Wed, 30 Sep 2015 15:21:07 -0300 Subject: [PATCH] backup/restore: omit host if absent from config --- lib/tasks/backup.rake | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/tasks/backup.rake b/lib/tasks/backup.rake index 498f9dc..fea0cdf 100644 --- a/lib/tasks/backup.rake +++ b/lib/tasks/backup.rake @@ -25,8 +25,9 @@ task :backup => :check_backup_support do dump = File.join('tmp/backup', backup_name) + '.sql' database = $config['production']['database'] - host = $config['production']['host'] || 'localhost' - sh "pg_dump -h #{host} #{database} > #{dump}" + host = $config['production']['host'] + host = host && "-h #{host}" || "" + sh "pg_dump #{host} #{database} > #{dump}" sh 'tar', 'chaf', backup_file, dump, *dirs rm_f dump @@ -82,15 +83,16 @@ task :restore => :check_backup_support do database = $config['production']['database'] username = $config['production']['username'] - host = $config['production']['host'] || 'localhost' + host = $config['production']['host'] + host = host && "-h #{host}" || "" puts "WARNING: backups should be restored to an empty database, otherwise" puts "data from the backup may not be loaded properly." puts puts 'You can remove the existing database and create a new one with:' puts - puts "$ sudo -u postgres dropdb -h #{host} #{database}" - puts "$ sudo -u postgres createdb -h #{host} #{database} --owner #{username}" + puts "$ sudo -u postgres dropdb #{host} #{database}" + puts "$ sudo -u postgres createdb #{host} #{database} --owner #{username}" puts print "Are you sure you want to continue (y/N)? " response = $stdin.gets.strip -- libgit2 0.21.2