Commit b5fff02ebdc764821500a136bc838b5cf31513d4

Authored by Antonio Terceiro
1 parent d8943451

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 25 dump = File.join('tmp/backup', backup_name) + '.sql'
26 26  
27 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 32 sh 'tar', 'chaf', backup_file, dump, *dirs
32 33 rm_f dump
... ... @@ -82,15 +83,16 @@ task :restore => :check_backup_support do
82 83  
83 84 database = $config['production']['database']
84 85 username = $config['production']['username']
85   - host = $config['production']['host'] || 'localhost'
  86 + host = $config['production']['host']
  87 + host = host && "-h #{host}" || ""
86 88  
87 89 puts "WARNING: backups should be restored to an empty database, otherwise"
88 90 puts "data from the backup may not be loaded properly."
89 91 puts
90 92 puts 'You can remove the existing database and create a new one with:'
91 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 96 puts
95 97 print "Are you sure you want to continue (y/N)? "
96 98 response = $stdin.gets.strip
... ...