public static function update($version, $backupBase){ if (!is_dir($backupBase)){ throw new \Exception("Backup directory $backupBase is not found"); } set_include_path( $backupBase . PATH_SEPARATOR . $backupBase . '/core/lib' . PATH_SEPARATOR . $backupBase . '/core/config' . PATH_SEPARATOR . $backupBase . '/3rdparty' . PATH_SEPARATOR . $backupBase . '/apps' . PATH_SEPARATOR . get_include_path() ); $tempDir = self::getTempDir(); Helper::mkdir($tempDir, true); $installed = Helper::getDirectories(); $sources = Helper::getSources($version); try{ $thirdPartyUpdater = new \OCA\Updater\Location\Thirdparty( $installed[Helper::THIRDPARTY_DIRNAME], $sources[Helper::THIRDPARTY_DIRNAME] ); $thirdPartyUpdater->update($tempDir . '/' . Helper::THIRDPARTY_DIRNAME); self::$processed[] = $thirdPartyUpdater; $coreUpdater = new \OCA\Updater\Location\Core( $installed[Helper::CORE_DIRNAME], $sources[Helper::CORE_DIRNAME] ); $coreUpdater->update($tempDir . '/' . Helper::CORE_DIRNAME); self::$processed[] = $coreUpdater; $appsUpdater = new \OCA\Updater\Location\Apps( '', //TODO: put smth really helpful here ;) $sources[Helper::APP_DIRNAME] ); $appsUpdater->update($tempDir . '/' . Helper::APP_DIRNAME); self::$processed[] = $appsUpdater; } catch (\Exception $e){ self::rollBack(); self::cleanUp(); throw $e; } // zip backup $zip = new \ZipArchive(); if ($zip->open($backupBase . ".zip", \ZIPARCHIVE::CREATE) === true){ Helper::addDirectoryToZip($zip, $backupBase); $zip->close(); \OCP\Files::rmdirr($backupBase); } return true; }
public static function update($version, $backupBase) { if (!is_dir($backupBase)) { throw new \Exception("Backup directory {$backupBase} is not found"); } // Switch include paths to backup $pathsArray = explode(PATH_SEPARATOR, get_include_path()); $pathsTranslated = []; foreach ($pathsArray as $path) { //Update all 3rdparty paths if (preg_match('|^' . preg_quote(\OC::$THIRDPARTYROOT . '/3rdparty') . '|', $path)) { $pathsTranslated[] = preg_replace('|^' . preg_quote(\OC::$THIRDPARTYROOT . '/3rdparty') . '|', $backupBase . '/3rdparty', $path); continue; } // Update all OC webroot paths $pathsTranslated[] = preg_replace('|^' . preg_quote(\OC::$SERVERROOT) . '|', $backupBase, $path); } set_include_path(implode(PATH_SEPARATOR, $pathsTranslated)); $tempDir = self::getTempDir(); Helper::mkdir($tempDir, true); $installed = Helper::getDirectories(); $sources = Helper::getSources($version); try { $thirdPartyUpdater = new \OCA\Updater\Location\Thirdparty($installed[Helper::THIRDPARTY_DIRNAME], $sources[Helper::THIRDPARTY_DIRNAME]); $thirdPartyUpdater->update($tempDir . '/' . Helper::THIRDPARTY_DIRNAME); self::$processed[] = $thirdPartyUpdater; $coreUpdater = new \OCA\Updater\Location\Core($installed[Helper::CORE_DIRNAME], $sources[Helper::CORE_DIRNAME]); $coreUpdater->update($tempDir . '/' . Helper::CORE_DIRNAME); self::$processed[] = $coreUpdater; $appsUpdater = new \OCA\Updater\Location\Apps('', $sources[Helper::APP_DIRNAME]); $appsUpdater->update($tempDir . '/' . Helper::APP_DIRNAME); self::$processed[] = $appsUpdater; } catch (\Exception $e) { self::rollBack(); self::cleanUp(); throw $e; } // zip backup $zip = new \ZipArchive(); if ($zip->open($backupBase . ".zip", \ZIPARCHIVE::CREATE) === true) { Helper::addDirectoryToZip($zip, $backupBase); $zip->close(); \OCP\Files::rmdirr($backupBase); } return true; }
/** * Perform backup * @return string */ public static function create($version) { $collection = new Collection(); $installed = Helper::getDirectories(); $sources = Helper::getSources($version); $thirdPartyUpdater = new \OCA\Updater\Location\Thirdparty($installed[Helper::THIRDPARTY_DIRNAME], $sources[Helper::THIRDPARTY_DIRNAME]); $coreUpdater = new \OCA\Updater\Location\Core($installed[Helper::CORE_DIRNAME], $sources[Helper::CORE_DIRNAME]); $appUpdater = new \OCA\Updater\Location\Apps($installed[Helper::APP_DIRNAME], ''); $thirdPartyFiles = $thirdPartyUpdater->collect(true); $coreFiles = $coreUpdater->collect(true); $appFiles = $appUpdater->collect(true); $locations = array(Helper::THIRDPARTY_DIRNAME => $thirdPartyFiles['old'], Helper::CORE_DIRNAME => $coreFiles['old'], Helper::APP_DIRNAME => $appFiles['old']); foreach ($locations as $type => $dirs) { foreach ($dirs as $name => $path) { Helper::checkr($path, $collection); } } if (count($collection->getNotReadable()) || count($collection->getNotWritable())) { $e = new PermissionException(); $e->setCollection($collection); throw $e; } try { Helper::mkdir(self::getPath(), true); foreach ($locations as $type => $dirs) { $backupFullPath = self::getPath() . '/' . $type . '/'; Helper::mkdir($backupFullPath, true); foreach ($dirs as $name => $path) { Helper::copyr($path, $backupFullPath . $name); } } } catch (\Exception $e) { \OC::$server->getLogger()->error('Backup creation failed. Disk full?', ['app' => 'updater']); self::cleanUp(); throw new FsException($e->getMessage()); } return self::getPath(); }