Exemple #1
0
	/**
	 * Builds directories for all buckets and pickupdir
	 *
	 * @param \BackupStore $store
	 * @return int returnstate
	 * @author : Rafał Trójniak rafal@trojniak.net
	 */
	function run(\BackupStore $store)
	{
		echo "== Build\n";
		$dirs=$store->getDirs();
		$dirs['pickup']=$store->getPickup();
		$ret=0;

		foreach($dirs as $id=>$dir){
			echo "[$id]:";
			$path=$dir->getPath();
			if(!is_dir($path)){
				echo "\tC";
				if(!mkdir($path, 0777, true)){
					echo "! - failed to create";
					$ret++;
				}
			}
			echo "\n";
		}

		if($ret===0){
			return true;
		}

		return $ret;
	}
	/**
	 * Run the command
	 *
	 * @param \BackupStore $store
	 * @return int Status of the command (to shell)
	 * @author : Rafał Trójniak rafal@trojniak.net
	 */
	function run(\BackupStore $store)
	{
		echo "== List pickups\n";
		$pickup=$store->getPickup();
		foreach($pickup->getBackups() as $backup){
			echo $backup->getCreation()->format('Y-m-d H:i T')."\n";
		}
		return true;
	}
	/**
	 * Cleans pickup according by rules
	 *
	 * @param \BackupStore $store
	 * @return int returnstate
	 * @author : Rafał Trójniak rafal@trojniak.net
	 */
	function run(\BackupStore $store)
	{
		echo "== Delete old pickup\n";
		$pickup=$store->getPickup();
		$toClean=$pickup->clean();
		foreach($toClean as $backup){
			echo "\t-\t".$backup->getCreation()->format(\DateTime::ISO8601)."\n";
		}
		return true;
	}
	/**
	 * 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);
	}
	/**
	 * Runs nagios checks based on flags
	 *
	 * @param \BackupStore $store
	 * @return int returnstate
	 * @author : Rafał Trójniak rafal@trojniak.net
	 */
	function run(\BackupStore $store)
	{
		$dir = $store->getDir($this->bucket);
		if(is_null($dir)){
			throw new \RuntimeException("Cannot find dir with name ".$this->bucket);
		}

		$states=array(0=>true);
		$output=array();

		if(in_array('size', $this->checks)){
			list($ret,$comment,$perf) = $results = $this->checkSize($dir);
			$states[$ret]=true;
			$output['size']=$results;
		}
		if(in_array('count', $this->checks)){
			list($ret,$comment,$perf) = $results =  $this->checkCount($dir);
			$states[$ret]=true;
			$output['count']=$results;
		}
		if(in_array('oldest', $this->checks)){
			list($ret,$comment,$perf) = $results = $this->checkOldest($dir);
			$states[$ret]=true;
			$output['oldest']= $results;
		}
		if(in_array('newest', $this->checks)){
			list($ret,$comment,$perf) = $results = $this->checkNewest($dir);
			$states[$ret]=true;
			$output['newest']=$results;
		}

		$ret=max(array_keys($states));

		$message=array();

		foreach($output as $plugin=>$vals){
			$message[]=$plugin."[".$this->retState($vals[0]).':'.$vals[1]."]";
		}

		$message=implode('; ',$message)."|";

		// Adding performance
		foreach($output as $plugin=>$vals){
			$message.=$plugin."[".implode(' ',$vals[2])."] ";
		}

		echo $message."\n";

		return $ret;
	}
Exemple #6
0
	/**
	 * Runs cleanning command on all pickupdirs
	 *
	 * @param \BackupStore $store
	 * @return int returnstate
	 * @author : Rafał Trójniak rafal@trojniak.net
	 */
	function run(\BackupStore $store)
	{
		echo "== Clean\n";
		$dirs=$store->getDirs();
		foreach($dirs as $id=>$dir){
			echo "[$id]:\n";
			$toClean=$dir->clean();
			foreach($toClean as $backup){
				echo "\t-\t".$backup->getCreation()->format(\DateTime::ISO8601)."\n";

			}
		}
		return true;
	}
	/**
	 * Runs rotating (rotates backup from pickup to backupdirs)
	 *
	 * @param \BackupStore $store
	 * @return int returnstate
	 * @author : Rafał Trójniak rafal@trojniak.net
	 */
	function run(\BackupStore $store)
	{
		echo "== List rotating\n";
		$dirs=$store->getDirs();
		$pickup=$store->getPickup();
		foreach($dirs as $id=>$dir){
			echo "[$id]:\n";
			$pick=$dir->pickup($pickup);
			foreach($pick as $backup){
				echo "\t+\t".$backup->getCreation()->format(\DateTime::ISO8601)."\n";

			}
		}
		return true;
	}
	/**
	 * Prints bucket contents
	 *
	 * @param \BackupStore $store
	 * @return int returnstate
	 * @author : Rafał Trójniak rafal@trojniak.net
	 */
	function run(\BackupStore $store)
	{
		if($this->bucket!==false){
			$dir=$store->getDir($this->bucket);
			if(is_null($dir)){
				throw new \RuntimeException('Bucket "'.addslashes($this->bucket).'" not found');
			}
			$this->listBackup($dir);
		}else{
			echo "== List backups\n";
			$dirs=$store->getDirs();
			foreach($dirs as $id=>$dir){
				echo "[$id]:\n";
				$this->listBackup($dir);
			}
		}
		return true;
	}