Class: Wordmove::Actions::BackupLocalDb
- Inherits:
-
Object
- Object
- Wordmove::Actions::BackupLocalDb
- Extended by:
- LightService::Action
- Includes:
- Helpers
- Defined in:
- lib/wordmove/actions/backup_local_db.rb
Overview
Take a backup of the local database and save it in wp-content/ folder.
Class Method Summary collapse
- .compress_command(context) ⇒ Object
- .dump_command(context) ⇒ Object
-
.execute ⇒ LightService::Context
Action’s context.
Class Method Details
.compress_command(context) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/wordmove/actions/backup_local_db.rb', line 58 def self.compress_command(context) command = ['nice'] command << '-n' command << '0' command << 'gzip' command << '-9' command << '-f' command << "\"#{context.db_paths.backup.local.path}\"" command.join(' ') end |
.dump_command(context) ⇒ Object
54 55 56 |
# File 'lib/wordmove/actions/backup_local_db.rb', line 54 def self.dump_command(context) "wp db export #{context.db_paths.backup.local.path} --allow-root --quiet" end |
.execute ⇒ LightService::Context
Returns Action’s context.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/wordmove/actions/backup_local_db.rb', line 23 executed do |context| context.logger.task 'Backup local DB' if simulate?(cli_options: context.) context.logger.info 'A backup of the local DB would have been saved into ' \ "#{context.db_paths.backup.local.gzipped_path}, " \ 'but you\'re simulating' next context end context.logger.task_step true, dump_command(context) begin system(dump_command(context), exception: true) rescue RuntimeError, SystemExit => e context.fail_and_return!("Local command status reports an error: #{e.}") end context.logger.task_step true, compress_command(context) begin system(compress_command(context), exception: true) rescue RuntimeError, SystemExit => e context.fail_and_return!("Local command status reports an error: #{e.}") end context.logger.success( "Backup saved at #{context.db_paths.backup.local.gzipped_path}" ) end |