/**
	 * Runs transformation commnad on backup
	 *
	 * @param \BackupStore $store
	 * @return int returnstate
	 * @author : Rafał Trójniak rafal@trojniak.net
	 */
	function run(\BackupStore $store)
	{
		echo "== Transform\n";
		$fileInfo= new \SplFileInfo($this->path);
		$backup = \Backup::create($fileInfo);
		return $backup->transform();
	}
Exemple #2
0
 private function _create_backup($files, $description)
 {
     $file = $this->_backup_store->new_backup_file();
     $bkp = new Backup($file);
     $this->_chdir_to_epesi();
     $success = $bkp->create($files, $description, $this->_backup_dir);
     $this->_chdir_back();
     return $success ? $bkp : false;
 }
	/**
	 * Verify backup using sumfile
	 *
	 * @param \BackupStore $store
	 * @return int returnstate
	 * @author : Rafał Trójniak rafal@trojniak.net
	 */
	function run(\BackupStore $store)
	{
		echo "== Verify\n";
		if(is_string($this->backup)){
			$fileinfo = new \SplFileInfo($this->backup);
			$backup=\Backup::create($fileinfo);
			$backups=array($backup);
		}else{
			$pickup = $store->getPickup();
			$backups=$pickup->getBackups();
		}
		return $this->runVerify($backups,$store);
	}
Exemple #4
0
 public static function backup($filename, $channelId, $removeAfterBackup = false)
 {
     $serv = StorageServer::getFreestServer();
     $relativepath = "uploads/{$channelId}/{$filename}";
     if ($serv !== false) {
         $hash = hash_hmac('sha256', $serv->address, $serv->private_key);
         $err = file_get_contents($serv->address . 'mkdir.php?cid=' . $channelId . '&hash=' . $hash);
         $filepath = ROOT . $relativepath;
         $addr = preg_replace("#^https?://([a-zA-Z0-9.-]+)(/.*)?\$#", "\$1", $serv->address);
         shell_exec("scp {$filepath} " . $serv->user . "@{$addr}:" . $serv->path . $relativepath . "");
         if ($removeAfterBackup) {
             unlink($filepath);
         }
         if (class_exists('Backup')) {
             Backup::create(array('channel_id' => $channelId, 'filepath' => $filepath, 'server' => $serv->address));
         }
     }
     return $serv->address . $relativepath;
 }
Exemple #5
0
 /**
  * Método para crear una copia de seguridad
  * 
  * @param type $data Input del post
  * @param string $path Ruta donde se almacenará la copia de seguridad
  * @param type $database Pull de conexión
  * @return boolean|\Backup
  */
 public static function createBackup($data, $path = '', $database = '')
 {
     $obj = new Backup($data);
     $obj->archivo = "backup-" . ($obj->count() + 1) . ".sql.gz";
     $obj->usuario_id = Session::get('id');
     //Inicio transacción
     ActiveRecord::beginTrans();
     if (!$obj->create()) {
         ActiveRecord::rollbackTrans();
         return FALSE;
     }
     if (empty($path)) {
         $path = APP_PATH . 'temp/backup/';
     }
     if (!is_writable($path)) {
         ActiveRecord::rollbackTrans();
         DwMessage::error('Error: BKP-CRE001. El directorio de las copias de seguridad no tiene permisos de escritura.');
         return false;
     }
     $file = $path . $obj->archivo;
     $system = $obj->_getSystem();
     $database = empty($databases) ? Config::get('config.application.database') : $database;
     $config = $obj->_getConfig($database);
     $exec = "{$system} -h " . $config['host'] . " -u " . $config['username'] . " --password="******" --opt --default-character-set=latin1 " . $config['name'] . " | gzip > {$file}";
     system($exec, $resultado);
     if ($resultado) {
         ActiveRecord::rollbackTrans();
         DwMessage::error('Error: BKP-CRE002. Se ha producido un error al intentar crear una nueva copia de seguridad.');
         return false;
     }
     $tamano = filesize($file);
     $clase = array(" Bytes", " KB", " MB", " GB", " TB");
     $obj->tamano = round($tamano / pow(1024, $i = floor(log($tamano, 1024))), 2) . $clase[$i];
     $obj->update();
     @chmod($file, 0744);
     ActiveRecord::commitTrans();
     if ($obj) {
         DwAudit::debug("Se crea una copia de seguridad bajo la denominación: {$obj->denominacion}");
     }
     return $obj;
 }
Exemple #6
0
//Step 1 - fetch & extract
if (!App::getSource($packageUrl, $packageVersion)) {
    try {
        //Do we have any remains of the previous update attempt?
        Downloader::cleanUp($packageVersion);
        Downloader::getPackage($packageUrl, $packageVersion);
        App::setSource($packageUrl, $packageVersion, true);
        \OCP\JSON::success(array());
    } catch (\Exception $e) {
        App::log($e->getMessage());
        \OCP\JSON::error(array('msg' => 'Unable to fetch package'));
    }
    exit;
}
//Step 2 - backup & update
//Do we have any remains of the previous update attempt?
Updater::cleanUp();
try {
    $backupPath = Backup::create();
    App::setSource($packageUrl, $packageVersion, false);
    Updater::update($packageVersion, $backupPath);
    //Cleanup
    Downloader::cleanUp($packageVersion);
    Updater::cleanUp();
    \OCP\JSON::success(array('backup' => $backupPath . '.zip'));
} catch (\Exception $e) {
    App::log($e->getMessage());
    App::setSource($packageUrl, $packageVersion, false);
    \OCP\JSON::error(array('msg' => 'Failed to create backup'));
}
exit;
Exemple #7
0
$page = 'backups';
$_user_location = 'admin';

$course = $_POST['course'];
require(AT_INCLUDE_PATH.'../mods/_core/backups/classes/Backup.class.php');

$Backup = new Backup($db);

if (isset($_POST['cancel'])) {
	$msg->addFeedback('CANCELLED');
	header('Location: index.php');
	exit;
} else if (isset($_POST['submit'])) {

	$Backup->setCourseID($_POST['course']);
	$error = $Backup->create($_POST['description']);
	if ($error !== FALSE) {
		$msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
		header('Location: index.php');
		exit;
	}
}

require(AT_INCLUDE_PATH.'header.inc.php');

?>


<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<div class="input-form">
Exemple #8
0
 public function create_backup_of_modified_files()
 {
     $files = $this->files_modified();
     if (empty($files)) {
         return '';
     }
     $release_package = substr($this->file, 0, -4);
     do {
         $random_string = substr(str_shuffle("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 12);
         $backup_file = "modified_since_{$release_package}_{$random_string}.bkp.zip";
     } while (file_exists($backup_file));
     $b = new Backup($backup_file);
     $b->create($files, "Modified files backup");
     return $backup_file;
 }
	/**
	 * Returns backup list
	 *
	 * @return array
	 * @author : Rafał Trójniak rafal@trojniak.net
	 */
	public function getBackups()
	{
		$this->lock();

		if(is_null($this->backups))
		{
			$this->backups=array();
			$dir = new DirectoryIterator( $this->getPath());
			foreach ($dir as $fileinfo)
			{

				// Removing '..'
				if ($fileinfo->isDot() or !$fileinfo->isDir()) {
					continue;
				}
				// Checking dotfile
				$name=$fileinfo->getFileName();
				if( $name[0]=='.') {
					continue;
				}

				$backup = Backup::create($fileinfo);
				$this->addBackup($backup);
			}
			ksort($this->backups);
		}
		return $this->backups;
	}
Exemple #10
0
    $packageVersionArray = explode('.', $packageVersion);
    Helper::checkVersion($packageVersionArray, $packageVersion);
    //Some cleanup first
    Downloader::cleanUp($packageVersion);
    if (!Downloader::isClean($packageVersion)) {
        $message = App::$l10n->t('Upgrade is not possible. Your web server does not have permission to remove the following directory:');
        $message .= '<br />' . Downloader::getPackageDir($packageVersion);
        $message .= '<br />' . App::$l10n->t('Update permissions on this directory and its content or remove it manually first.');
        throw new \Exception($message);
    }
    Updater::cleanUp();
    if (!Updater::isClean()) {
        $message = App::$l10n->t('Upgrade is not possible. Your web server does not have permission to remove the following directory:');
        $message .= '<br />' . Updater::getTempDir();
        $message .= '<br />' . App::$l10n->t('Update permissions on this directory and its content or remove it manually first.');
        throw new \Exception($message);
    }
    $backupPath = Backup::create($packageVersion);
    \OCP\JSON::success(array('backup' => $backupPath, 'version' => $packageVersion, 'url' => $packageUrl));
} catch (PermissionException $e) {
    //Something is not writable|readable
    \OCP\JSON::error(array('message' => $e->getExtendedMessage()));
} catch (FsException $e) {
    //Backup failed
    App::log($e->getMessage());
    \OCP\JSON::error(array('message' => $e->getMessage()));
} catch (\Exception $e) {
    //Something went wrong. We don't know what
    App::log($e->getMessage());
    \OCP\JSON::error(array('message' => $e->getMessage()));
}
	/**
	 *  Clones backup by recursive copying directory
	 *
	 * @param \Backup $toClone
	 * @param string $destDir Destination directory
	 * @author : Rafał Trójniak rafal@trojniak.net
	 */
	public function cloneBackup( \Backup $toClone,  $destDir)
	{
		mkdir($destDir);
		// Crypt files
		foreach($toClone as $item){
			$newName=
				$destDir.
				DIRECTORY_SEPARATOR.
				$item->getName().
				$this->extension;
			$this->cryptFile($item->getPath(), $newName);
		}
		// Crypt old sumfile
			$newName=
				$destDir.
				DIRECTORY_SEPARATOR.
				\Backup::SUMFILE.
				$this->extension;
		$this->cryptFile($toClone->getSumfilePath(),$newName);

		$newBackup=\Backup::create(new \SplFileInfo($destDir));
		$newBackup->fill();
	}