/** * @param string $tar_filename * @param string $tar_dir * @param string $filename * @return bool */ private function _archive($tar_filename, $tar_dir, $filename) { //Archive the backup to DIR_BACKUP, delete tmp files in directory $this->backup_dir //And create record in the database for created archive. //generate errors: No space on device (log to message as error too), No permissons, Others //return Success or failed. $command = 'tar -C ' . $tar_dir . ' -czvf ' . $tar_filename . ' ' . $filename . ' > /dev/null'; if (isFunctionAvailable('system')) { system($command, $exit_code); } else { $exit_code = 1; } if ($exit_code) { $this->load->library('targz'); $targz = new Atargz(); $targz->makeTar($tar_dir . $filename, $tar_filename); } if (!file_exists($tar_filename)) { $this->processError('Archive error', 'Error: cannot to pack ' . $tar_filename . "\n Exit code:" . $exit_code); return false; } @chmod($tar_filename, 0777); $this->_removeDir($tar_dir . $filename); return true; }
function compressTarGZ($tar_filename, $tar_dir, $compress_level = 5) { $compress_level = $compress_level < 1 || $compress_level > 9 ? 5 : $compress_level; $exit_code = 0; if (pathinfo($tar_filename, PATHINFO_EXTENSION) == 'gz') { $filename = rtrim($tar_filename, '.gz'); } else { $filename = $tar_filename . '.tar.gz'; } $tar = rtrim($tar_filename, '.gz'); //remove archive if exists if (is_file($tar_filename)) { unlink($tar_filename); } if (is_file($filename)) { unlink($filename); } if (is_file($tar)) { unlink($tar); } if (class_exists('PharData')) { try { $a = new PharData($tar); $a->buildFromDirectory($tar_dir); // this code creates tar-file if (file_exists($tar)) { // remove tar-file after zipping gzip($tar, $compress_level); unlink($tar); } } catch (Exception $e) { $error = new AError($e->getMessage()); $error->toLog()->toDebug(); $exit_code = 1; } } else { $exit_code = 1; } if ($exit_code) { $registry = Registry::getInstance(); $registry->get('load')->library('targz'); $targz = new Atargz(); return $targz->makeTar($tar_dir . $tar_filename, $filename, $compress_level); } else { return true; } }