Commit b5fff02ebdc764821500a136bc838b5cf31513d4
1 parent
d8943451
Exists in
master
and in
21 other branches
backup/restore: omit host if absent from config
Showing
1 changed file
with
7 additions
and
5 deletions
Show diff stats
lib/tasks/backup.rake
@@ -25,8 +25,9 @@ task :backup => :check_backup_support do | @@ -25,8 +25,9 @@ task :backup => :check_backup_support do | ||
25 | dump = File.join('tmp/backup', backup_name) + '.sql' | 25 | dump = File.join('tmp/backup', backup_name) + '.sql' |
26 | 26 | ||
27 | database = $config['production']['database'] | 27 | database = $config['production']['database'] |
28 | - host = $config['production']['host'] || 'localhost' | ||
29 | - sh "pg_dump -h #{host} #{database} > #{dump}" | 28 | + host = $config['production']['host'] |
29 | + host = host && "-h #{host}" || "" | ||
30 | + sh "pg_dump #{host} #{database} > #{dump}" | ||
30 | 31 | ||
31 | sh 'tar', 'chaf', backup_file, dump, *dirs | 32 | sh 'tar', 'chaf', backup_file, dump, *dirs |
32 | rm_f dump | 33 | rm_f dump |
@@ -82,15 +83,16 @@ task :restore => :check_backup_support do | @@ -82,15 +83,16 @@ task :restore => :check_backup_support do | ||
82 | 83 | ||
83 | database = $config['production']['database'] | 84 | database = $config['production']['database'] |
84 | username = $config['production']['username'] | 85 | username = $config['production']['username'] |
85 | - host = $config['production']['host'] || 'localhost' | 86 | + host = $config['production']['host'] |
87 | + host = host && "-h #{host}" || "" | ||
86 | 88 | ||
87 | puts "WARNING: backups should be restored to an empty database, otherwise" | 89 | puts "WARNING: backups should be restored to an empty database, otherwise" |
88 | puts "data from the backup may not be loaded properly." | 90 | puts "data from the backup may not be loaded properly." |
89 | puts | 91 | puts |
90 | puts 'You can remove the existing database and create a new one with:' | 92 | puts 'You can remove the existing database and create a new one with:' |
91 | puts | 93 | puts |
92 | - puts "$ sudo -u postgres dropdb -h #{host} #{database}" | ||
93 | - puts "$ sudo -u postgres createdb -h #{host} #{database} --owner #{username}" | 94 | + puts "$ sudo -u postgres dropdb #{host} #{database}" |
95 | + puts "$ sudo -u postgres createdb #{host} #{database} --owner #{username}" | ||
94 | puts | 96 | puts |
95 | print "Are you sure you want to continue (y/N)? " | 97 | print "Are you sure you want to continue (y/N)? " |
96 | response = $stdin.gets.strip | 98 | response = $stdin.gets.strip |