Read about our upcoming Code of Conduct on this issue

Commit d1d13856 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Merge branch 'report_backup_db_success' into 'master'

Report success/failure of DB backup commands
......@@ -11,23 +11,29 @@ def initialize
end
def dump
case config["adapter"]
success = case config["adapter"]
when /^mysql/ then
print "Dumping MySQL database #{config['database']} ... "
system('mysqldump', *mysql_args, config['database'], out: db_file_name)
when "postgresql" then
print "Dumping PostgreSQL database #{config['database']} ... "
pg_env
system('pg_dump', config['database'], out: db_file_name)
end
report_success(success)
end
def restore
case config["adapter"]
success = case config["adapter"]
when /^mysql/ then
print "Restoring MySQL database #{config['database']} ... "
system('mysql', *mysql_args, config['database'], in: db_file_name)
when "postgresql" then
print "Restoring PostgreSQL database #{config['database']} ... "
pg_env
system('psql', config['database'], '-f', db_file_name)
end
report_success(success)
end
protected
......@@ -54,5 +60,13 @@ def pg_env
ENV['PGPORT'] = config["port"].to_s if config["port"]
ENV['PGPASSWORD'] = config["password"].to_s if config["password"]
end
def report_success(success)
if success
puts '[DONE]'.green
else
puts '[FAILED]'.red
end
end
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment