Commit 9e6fc8b5269f8583e88c67c7cdc356f76a8237ed
1 parent
68590fdd
Exists in
spb-stable
and in
3 other branches
Report failure of DB backup commands
Showing
1 changed file
with
16 additions
and
2 deletions
Show diff stats
lib/backup/database.rb
| @@ -11,23 +11,29 @@ module Backup | @@ -11,23 +11,29 @@ module Backup | ||
| 11 | end | 11 | end |
| 12 | 12 | ||
| 13 | def dump | 13 | def dump |
| 14 | - case config["adapter"] | 14 | + success = case config["adapter"] |
| 15 | when /^mysql/ then | 15 | when /^mysql/ then |
| 16 | + print "Dumping MySQL database #{config['database']} ... " | ||
| 16 | system('mysqldump', *mysql_args, config['database'], out: db_file_name) | 17 | system('mysqldump', *mysql_args, config['database'], out: db_file_name) |
| 17 | when "postgresql" then | 18 | when "postgresql" then |
| 19 | + print "Dumping PostgreSQL database #{config['database']} ... " | ||
| 18 | pg_env | 20 | pg_env |
| 19 | system('pg_dump', config['database'], out: db_file_name) | 21 | system('pg_dump', config['database'], out: db_file_name) |
| 20 | end | 22 | end |
| 23 | + report_success(success) | ||
| 21 | end | 24 | end |
| 22 | 25 | ||
| 23 | def restore | 26 | def restore |
| 24 | - case config["adapter"] | 27 | + success = case config["adapter"] |
| 25 | when /^mysql/ then | 28 | when /^mysql/ then |
| 29 | + print "Restoring MySQL database #{config['database']} ... " | ||
| 26 | system('mysql', *mysql_args, config['database'], in: db_file_name) | 30 | system('mysql', *mysql_args, config['database'], in: db_file_name) |
| 27 | when "postgresql" then | 31 | when "postgresql" then |
| 32 | + print "Restoring PostgreSQL database #{config['database']} ... " | ||
| 28 | pg_env | 33 | pg_env |
| 29 | system('psql', config['database'], '-f', db_file_name) | 34 | system('psql', config['database'], '-f', db_file_name) |
| 30 | end | 35 | end |
| 36 | + report_success(success) | ||
| 31 | end | 37 | end |
| 32 | 38 | ||
| 33 | protected | 39 | protected |
| @@ -54,5 +60,13 @@ module Backup | @@ -54,5 +60,13 @@ module Backup | ||
| 54 | ENV['PGPORT'] = config["port"].to_s if config["port"] | 60 | ENV['PGPORT'] = config["port"].to_s if config["port"] |
| 55 | ENV['PGPASSWORD'] = config["password"].to_s if config["password"] | 61 | ENV['PGPASSWORD'] = config["password"].to_s if config["password"] |
| 56 | end | 62 | end |
| 63 | + | ||
| 64 | + def report_success(success) | ||
| 65 | + if success | ||
| 66 | + puts '[DONE]'.green | ||
| 67 | + else | ||
| 68 | + puts '[FAILED]'.red | ||
| 69 | + end | ||
| 70 | + end | ||
| 57 | end | 71 | end |
| 58 | end | 72 | end |