2015-07-03 00:00:30 +02:00
|
|
|
<?php
|
|
|
|
|
2015-07-10 19:07:14 +02:00
|
|
|
namespace Shikiryu\Backup\Backup;
|
2015-07-03 00:00:30 +02:00
|
|
|
|
2015-08-17 13:16:28 +02:00
|
|
|
abstract class BackupAbstract
|
2015-07-03 00:00:30 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
protected $_filesToBackup;
|
|
|
|
protected $_streamsToBackup;
|
|
|
|
|
|
|
|
/**
|
2015-07-12 20:34:54 +02:00
|
|
|
* @param array $config
|
2015-07-03 00:00:30 +02:00
|
|
|
*/
|
2015-07-12 20:34:54 +02:00
|
|
|
function __construct($config = array())
|
2015-07-03 00:00:30 +02:00
|
|
|
{
|
2015-07-12 20:34:54 +02:00
|
|
|
foreach ($config as $name => $value) {
|
|
|
|
$this->$name = $value;
|
|
|
|
}
|
|
|
|
$this->_filesToBackup = array();
|
2015-07-03 00:00:30 +02:00
|
|
|
$this->_streamsToBackup = array();
|
|
|
|
}
|
|
|
|
|
2015-07-12 20:34:54 +02:00
|
|
|
/**
|
|
|
|
* Magic setter method
|
|
|
|
*
|
|
|
|
* @param $name
|
|
|
|
* @param $value
|
|
|
|
*/
|
|
|
|
public function __set($name, $value)
|
|
|
|
{
|
|
|
|
$this->$name = $value;
|
|
|
|
}
|
|
|
|
|
2015-07-09 00:46:17 +02:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getFilesToBackup()
|
|
|
|
{
|
|
|
|
return $this->_filesToBackup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getStreamsToBackup()
|
|
|
|
{
|
|
|
|
return $this->_streamsToBackup;
|
|
|
|
}
|
|
|
|
|
2015-07-03 00:00:30 +02:00
|
|
|
/**
|
|
|
|
* Add the current date with the given format into the files names
|
|
|
|
*
|
|
|
|
* @param string $format
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
2015-07-12 20:53:15 +02:00
|
|
|
public function addDate($format = 'Ymd')
|
2015-07-03 00:00:30 +02:00
|
|
|
{
|
|
|
|
$tmpFiles = array();
|
2015-07-12 20:34:54 +02:00
|
|
|
foreach ($this->_filesToBackup as $file => $name) {
|
2015-07-03 00:00:30 +02:00
|
|
|
$nameA = explode('.', $name);
|
|
|
|
$nameA[] = end($nameA);
|
2015-07-12 20:34:54 +02:00
|
|
|
$nameA[count($nameA) - 2] = date($format);
|
2015-07-03 00:00:30 +02:00
|
|
|
$name = implode('.', $nameA);
|
|
|
|
$tmpFiles[$file] = $name;
|
|
|
|
}
|
|
|
|
$this->_filesToBackup = $tmpFiles;
|
|
|
|
|
|
|
|
$tmpStream = array();
|
2015-07-12 20:34:54 +02:00
|
|
|
foreach ($this->_streamsToBackup as $name => $stream) {
|
2015-07-03 00:00:30 +02:00
|
|
|
$tmpStream[$name . '-' . date($format)] = $stream;
|
|
|
|
}
|
|
|
|
$this->_streamsToBackup = $tmpStream;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the current time with the given format into the files names
|
|
|
|
*
|
|
|
|
* @param string $format
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
2015-07-12 20:53:15 +02:00
|
|
|
public function addTime($format = 'his')
|
2015-07-03 00:00:30 +02:00
|
|
|
{
|
|
|
|
$tmpFiles = array();
|
2015-07-12 20:34:54 +02:00
|
|
|
foreach ($this->_filesToBackup as $file => $name) {
|
2015-07-03 00:00:30 +02:00
|
|
|
$nameA = explode('.', $name);
|
|
|
|
$nameA[] = end($nameA);
|
2015-07-12 20:34:54 +02:00
|
|
|
$nameA[count($nameA) - 2] = date($format);
|
2015-07-03 00:00:30 +02:00
|
|
|
$name = implode('.', $nameA);
|
|
|
|
$tmpFiles[$file] = $name;
|
|
|
|
}
|
|
|
|
$this->_filesToBackup = $tmpFiles;
|
|
|
|
|
|
|
|
$tmpStream = array();
|
2015-07-12 20:34:54 +02:00
|
|
|
foreach ($this->_streamsToBackup as $name => $stream) {
|
2015-07-03 00:00:30 +02:00
|
|
|
$tmpStream[$name . '-' . date($format)] = $stream;
|
|
|
|
}
|
|
|
|
$this->_streamsToBackup = $tmpStream;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
function backupToDropbox()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if all files got the minimum given size.
|
|
|
|
*
|
|
|
|
* @param int $fs
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2015-07-12 20:34:54 +02:00
|
|
|
function checkMinimumFilesize($fs)
|
|
|
|
{
|
|
|
|
foreach ($this->_filesToBackup as $file => $name) {
|
|
|
|
if (filesize($file) < $fs) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-07-03 00:00:30 +02:00
|
|
|
}
|
2015-07-12 20:34:54 +02:00
|
|
|
foreach ($this->_streamsToBackup as $name => $file) {
|
2015-07-03 00:00:30 +02:00
|
|
|
if (mb_strlen($file, 'utf-8') < $fs) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-07-12 20:34:54 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
2015-07-12 20:53:15 +02:00
|
|
|
abstract public function isValid();
|
2015-07-03 00:00:30 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|