Example #1
0
 /**
  * @return array
  */
 public function getFiles()
 {
     return (new Collection($this->get('files')))->filter(function ($file) {
         return File::isExisting($file) === true ? true : false;
     })->filter(function ($file) {
         return File::isFile($file) === true ? true : false;
     })->filter(function ($file) {
         return File::isReadable($file) === true ? true : false;
     })->sort('strnatcmp')->toArray();
 }
Example #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');
 }