mirror of
https://github.com/Chouchen/Shikiryu_Backup.git
synced 2021-06-30 16:02:14 +02:00
app
code
backup
exceptions
transport
Dropbox.php
Email.php
FTP.php
Factory.php
Folder.php
SFTP.php
TransportAbstract.php
Scenario.php
scenario
temp
docs
tests
.drone.yml
.gitignore
README.md
composer.json
composer.lock
phpmd.xml
phpunit.xml
55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Shikiryu\Backup\Transport;
|
|
|
|
use Exception;
|
|
use Shikiryu\Backup\Backup\BackupAbstract;
|
|
|
|
class Folder extends TransportAbstract
|
|
{
|
|
/**
|
|
* Folder to backup
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $folder;
|
|
|
|
public function __construct(BackupAbstract $backup, array $config = array())
|
|
{
|
|
parent::__construct($backup, $config);
|
|
|
|
if (!empty($this->folder)) {
|
|
$this->folder = sprintf('%s/', rtrim($this->folder, '/'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
public function send()
|
|
{
|
|
if ($this->backup->isDistant()) {
|
|
$this->backup = $this->backup->retrieve();
|
|
}
|
|
if ($this->backup->isLocal()) {
|
|
foreach ($this->backup->getFilesToBackup() as $file => $name) {
|
|
if (copy($file, $this->folder . $name) === false) {
|
|
throw new Exception(sprintf('Copy of %s in %s failed', $name, $this->folder));
|
|
}
|
|
}
|
|
foreach ($this->backup->getStreamsToBackup() as $name => $file) {
|
|
if (substr_count($name, '.') + 1 < 2) {
|
|
$name = 'backup' . $name . '.txt';
|
|
}
|
|
if (file_put_contents($this->folder . $name, $file) === false) {
|
|
throw new Exception(sprintf('Saving of %s in %s failed', $name, $this->folder));
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|