] [--root] [--zip_command_path=] [--mysqldump_command_path=] * * @todo errors should be bubbled from Backup, Scheduled_Backup and the like instead of being repeated. */ public function backup( $args, $assoc_args ) { add_action( 'hmbkp_mysqldump_started', function () { \WP_CLI::line( __( 'Backup: Dumping database...', 'backupwordpress' ) ); } ); add_action( 'hmbkp_archive_started', function () { \WP_CLI::line( __( 'Backup: Zipping everything up...', 'backupwordpress' ) ); } ); if ( ! empty( $assoc_args['destination'] ) ) { Path::get_instance()->set_path( $assoc_args['destination'] ); } Path::get_instance()->cleanup(); if ( ! empty( $assoc_args['root'] ) ) { Path::get_instance()->set_root( $assoc_args['root'] ); } if ( ( ! is_dir( Path::get_path() ) ) ) { \WP_CLI::error( __( 'Invalid backup path', 'backupwordpress' ) ); return false; } if ( ! is_dir( Path::get_root() ) || ! is_readable( Path::get_root() ) ) { \WP_CLI::error( __( 'Invalid root path', 'backupwordpress' ) ); return false; } $filename = 'backup.zip'; if ( isset( $assoc_args['archive_filename'] ) ) { $filename = $assoc_args['archive_filename']; } $hm_backup = new Backup( $filename ); if ( ! empty( $assoc_args['files_only'] ) ) { $hm_backup->set_type( 'file' ); } if ( ! empty( $assoc_args['database_only'] ) ) { $hm_backup->set_type( 'database' ); } if ( ! empty( $assoc_args['excludes'] ) ) { $hm_backup->set_excludes( new Excludes( $assoc_args['excludes'] ) ); } $hm_backup->run(); if ( file_exists( $hm_backup->get_backup_filepath() ) ) { \WP_CLI::success( __( 'Backup Complete: ', 'backupwordpress' ) . $hm_backup->get_backup_filepath() ); } else { \WP_CLI::error( __( 'Backup Failed', 'backupwordpress' ) ); } } } \WP_CLI::add_command( 'backupwordpress', 'HM\BackUpWordPress\CLI' );