Beispiel #1
0
 /**
  * @return string
  * @throws \Astrotomic\Backuplay\Exceptions\EntityIsNoDirectoryException
  * @throws \Astrotomic\Backuplay\Exceptions\FileIsntWritableException
  */
 public function getTempDir()
 {
     $dir = $this->get('temp_path.dir');
     $chmod = $this->get('temp_path.chmod');
     if (!(File::isDir($dir, false) === true ? true : false)) {
         try {
             $success = mkdir($dir, $chmod, true);
         } catch (\ErrorException $exception) {
             $success = false;
         }
         if (!$success) {
             throw new EntityIsNoDirectoryException($dir);
         }
     }
     File::isWritable($dir, true);
     return rtrim($dir, DIRECTORY_SEPARATOR);
 }
Beispiel #2
0
 /**
  * @return void
  * @throws \Astrotomic\Backuplay\Exceptions\EntityIsNoDirectoryException
  * @throws \Astrotomic\Backuplay\Exceptions\FileDoesNotExistException
  * @throws \Astrotomic\Backuplay\Exceptions\EntityIsNoFileException
  * @throws \Symfony\Component\Process\Exception\ProcessFailedException
  */
 public function fire()
 {
     $this->info('start backuplay');
     Event::fire(new BackupCreateBeforeCommand($this));
     $this->folders = $this->config->getFolders();
     $this->comment('backup folders: ' . implode(' ', $this->folders));
     $this->files = $this->config->getFiles();
     $this->comment('backup files: ' . implode(' ', $this->files));
     if ($this->isValidBackup()) {
         $this->runBeforeScripts();
         $tempDir = $this->config->getTempDir();
         $tempName = md5(uniqid(date('U'))) . '.' . $this->config->get('extension');
         $tempPath = $tempDir . DIRECTORY_SEPARATOR . $tempName;
         $tempMeta = $this->createMetaFile($tempPath);
         $zippy = Archive::load();
         $archive = $zippy->create($tempPath, ['backup_info.txt' => $tempMeta]);
         $this->unlink($tempMeta);
         if (count($this->folders) > 0) {
             $this->comment('add folders to archive');
             foreach ($this->folders as $folder) {
                 $this->comment('add folder: ' . $folder);
                 $archive->addMembers([$folder => $folder], true);
             }
         }
         if (count($this->files) > 0) {
             $this->comment('add files to archive');
             foreach ($this->files as $file) {
                 $this->comment('add file: ' . $file);
                 $archive->addMembers($file, false);
             }
         }
         File::isExisting($tempPath, true);
         File::isFile($tempPath, true);
         $this->info('created archive');
         $this->storeArchive($tempPath);
         $this->runAfterScripts();
     }
     Event::fire(new BackupCreateAfterCommand($this));
     $this->info('end backuplay');
 }