/** * Perform the file backup. * * @return bool Whether the backup completed successfully or not. */ public function backup() { if (!Backup_Utilities::is_exec_available() || !$this->get_zip_executable_path()) { return false; } // cd to the site root $command[] = 'cd ' . escapeshellarg(Path::get_root()); // Run the zip command with the recursive and quiet flags $command[] = '&& ' . escapeshellcmd($this->get_zip_executable_path()) . ' -rq'; // Save the zip file to the correct path $command[] = escapeshellarg($this->get_backup_filepath()) . ' ./'; // Pass exclude rules in if we have them if ($this->get_exclude_string()) { $command[] = '-x ' . $this->get_exclude_string(); } // Push all output to STDERR $command[] = '2>&1'; $command = implode(' ', $command); $output = $return_status = 0; exec($command, $output, $return_status); // Track any errors if ($output) { if ($return_status === 0) { $this->warning(__CLASS__, implode(', ', $output)); } else { $this->error(__CLASS__, implode(', ', $output)); } } return $this->verify_backup(); }
/** * @return bool */ public static function test() { return Backup_Utilities::is_exec_available(); }