public function backup()
{
if (!$this->get_zip_executable_path()) {
return false;
}
$command = array();
// 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();
}
$command = implode(' ', $command);
$process = new Process($command);
$process->setTimeout(HOUR_IN_SECONDS);
try {
$process->run();
} catch (\Exception $e) {
$this->error(__CLASS__, $e->getMessage());
}
if (!$process->isSuccessful()) {
/**
* Exit Code 18 is returned when an unreadable file is encountered during the zip process.
*
* Given the zip process still completes correctly and the unreadable file is simple skipped
* we don't want to treat 18 as an actual error.
*/
if ($process->getExitCode() !== 18) {
$this->error(__CLASS__, $process->getErrorOutput());
}
}
return $this->verify_backup();
}