Example #1
0
 /**
  * Clean old backups
  *
  * @param $maxAgeInDays
  * @return int
  */
 private function cleanOldBackups($maxAgeInDays)
 {
     $expireDate = Carbon::now()->subDays($maxAgeInDays);
     $oldBackups = Backup::where('created_at', '<', $expireDate)->get();
     foreach ($oldBackups as $oldBackup) {
         $oldBackup->delete();
     }
     return count($oldBackups);
 }
Example #2
0
 /**
  * Ask question about backup id
  *
  * @return bool
  */
 private function askBackupId()
 {
     $backups = BackupModel::all();
     if (!$backups) {
         $this->info(trans('renatio.backupmanager::lang.restore.no_backups'));
         return false;
     }
     $backupId = $this->getBackupIdOption($backups);
     if (!BackupModel::find($backupId)) {
         $this->error(trans('renatio.backupmanager::lang.restore.backup_not_exist'));
         return false;
     }
     $this->input->setOption('backup-id', $backupId);
     return true;
 }
 /**
  * Seed backups table
  *
  * @param $backups
  */
 private function seedBackupsTable($backups)
 {
     Backup::truncate();
     $data = [];
     foreach ($backups as $backup) {
         $data[] = ['id' => $backup->id, 'disk_name' => $backup->disk_name, 'file_path' => $backup->file_path, 'type' => $backup->type, 'filesystems' => $backup->filesystems, 'file_size' => $backup->getFileSize($backup->file_path), 'created_at' => $backup->created_at, 'updated_at' => $backup->updated_at];
     }
     Backup::insert($data);
 }
Example #4
0
 /**
  * Copy files action
  *
  * @return $this
  */
 public function copyFiles()
 {
     $this->fileHandler->copyFilesToStorage(Session::pull('backupZipFile'));
     Backup::saveRecord();
     return $this;
 }
Example #5
0
 /**
  * Get backup for restore action
  *
  * @return mixed
  * @throws ApplicationException
  */
 private function getBackupForRestore()
 {
     $checked = post('checked');
     if (count($checked) !== 1) {
         throw new ApplicationException(trans('renatio.backupmanager::lang.restore.invalid_check'));
     }
     try {
         return Backup::findOrFail($checked[0]);
     } catch (ModelNotFoundException $ex) {
         throw new ApplicationException(trans('renatio.backupmanager::lang.restore.invalid_check'));
     }
 }
Example #6
0
 /**
  * Unzip backup file
  *
  * @param $id
  * @return $this
  * @throws ApplicationException
  */
 private function unzipBackup($id)
 {
     $backup = Backup::findOrFail($id);
     $filePath = $this->getBackupFromStorage($backup);
     $zip = new ZipArchive();
     $res = $zip->open($filePath);
     if ($res === true) {
         $zip->extractTo(storage_path('temp'), ['db/dump.sql']);
         $zip->close();
         $backup->deleteNotLocalFile();
     } else {
         throw new ApplicationException(trans('renatio.backupmanager::lang.restore.open_error'));
     }
     return $this;
 }