Report failure of DB backup commands
This commit is contained in:
parent
68590fddd8
commit
9e6fc8b526
1 changed files with 16 additions and 2 deletions
|
@ -11,23 +11,29 @@ module Backup
|
||||||
end
|
end
|
||||||
|
|
||||||
def dump
|
def dump
|
||||||
case config["adapter"]
|
success = case config["adapter"]
|
||||||
when /^mysql/ then
|
when /^mysql/ then
|
||||||
|
print "Dumping MySQL database #{config['database']} ... "
|
||||||
system('mysqldump', *mysql_args, config['database'], out: db_file_name)
|
system('mysqldump', *mysql_args, config['database'], out: db_file_name)
|
||||||
when "postgresql" then
|
when "postgresql" then
|
||||||
|
print "Dumping PostgreSQL database #{config['database']} ... "
|
||||||
pg_env
|
pg_env
|
||||||
system('pg_dump', config['database'], out: db_file_name)
|
system('pg_dump', config['database'], out: db_file_name)
|
||||||
end
|
end
|
||||||
|
report_success(success)
|
||||||
end
|
end
|
||||||
|
|
||||||
def restore
|
def restore
|
||||||
case config["adapter"]
|
success = case config["adapter"]
|
||||||
when /^mysql/ then
|
when /^mysql/ then
|
||||||
|
print "Restoring MySQL database #{config['database']} ... "
|
||||||
system('mysql', *mysql_args, config['database'], in: db_file_name)
|
system('mysql', *mysql_args, config['database'], in: db_file_name)
|
||||||
when "postgresql" then
|
when "postgresql" then
|
||||||
|
print "Restoring PostgreSQL database #{config['database']} ... "
|
||||||
pg_env
|
pg_env
|
||||||
system('psql', config['database'], '-f', db_file_name)
|
system('psql', config['database'], '-f', db_file_name)
|
||||||
end
|
end
|
||||||
|
report_success(success)
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
@ -54,5 +60,13 @@ module Backup
|
||||||
ENV['PGPORT'] = config["port"].to_s if config["port"]
|
ENV['PGPORT'] = config["port"].to_s if config["port"]
|
||||||
ENV['PGPASSWORD'] = config["password"].to_s if config["password"]
|
ENV['PGPASSWORD'] = config["password"].to_s if config["password"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def report_success(success)
|
||||||
|
if success
|
||||||
|
puts '[DONE]'.green
|
||||||
|
else
|
||||||
|
puts '[FAILED]'.red
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue