data['backups'] = []; foreach (config('backup.backup.destination.disks') as $disk_name) { $disk = Storage::disk($disk_name); $adapter = $disk->getDriver()->getAdapter(); $files = $disk->allFiles(); // make an array of backup files, with their filesize and creation date foreach ($files as $k => $f) { // only take the zip files into account if (substr($f, -4) == '.zip' && $disk->exists($f)) { $this->data['backups'][] = [ 'file_path' => $f, 'file_name' => str_replace('backups/', '', $f), 'file_size' => $disk->size($f), 'last_modified' => $disk->lastModified($f), 'disk' => $disk_name, 'download' => ($adapter instanceof Local) ? true : false, ]; } } } // reverse the backups, so the newest one would be on top $this->data['backups'] = array_reverse($this->data['backups']); $this->data['title'] = 'Backups'; return view('Staff.backup.backup', $this->data); } /** * Create A Backup * * @return Illuminate\Http\RedirectResponse */ public function create() { try { ini_set('max_execution_time', 300); // start the backup process Artisan::call('backup:run'); $output = Artisan::output(); // log the results info("A new backup was initiated from the staff dashboard ".$output); // return the results as a response to the ajax call echo $output; } catch (Exception $e) { response($e->getMessage(), 500); } return 'success'; } /** * Download A Backup * * @param \Illuminate\Http\Request $request * @return Illuminate\Http\RedirectResponse */ public function download(Request $request) { $disk = Storage::disk($request->input('disk')); $file_name = $request->input('file_name'); $adapter = $disk->getDriver()->getAdapter(); if ($adapter instanceof Local) { $storage_path = $disk->getDriver()->getAdapter()->getPathPrefix(); if ($disk->exists($file_name)) { return response()->download($storage_path.$file_name); } else { abort(404, trans('backup.backup_doesnt_exist')); } } else { abort(404, trans('backup.only_local_downloads_supported')); } } /** * Deletes A Backup * * @param \Illuminate\Http\Request $request * @param $file_name * @return Illuminate\Http\RedirectResponse */ public function delete(Request $request, $file_name) { $disk = Storage::disk($request->input('disk')); if ($disk->exists($file_name)) { $disk->delete($file_name); return 'success'; } else { abort(404, trans('backup.backup_doesnt_exist')); } } }