&1"; exec($command, $output); Log::info('Backup ' . $dbName . ' db '); Log::Debug($output); } else { foreach (['data', 'scheme'] as $type) { $parameters = "--no-data"; if ($type == "data") { $parameters = "--no-create-info"; } $backupFile = $db_backup_path . '/' . $dbName . '_' . $type . '_' . date("Y-m-d", time()) . '.sql'; $command = "mysqldump --skip-comments " . $parameters . " -h localhost -u " . $dbUserName . " -p" . $dbPassword . " " . $dbName . " -r $backupFile 2>&1"; exec($command, $output); Log::info('Backup ' . $dbName . ' db ' . $type); Log::Debug($output); } } //STORAGE $command = "cp -R " . storage_path('app') . " " . storage_path('backups/tmp/storage'); exec($command, $output); Log::info('storage backup done'); Log::Debug($output); //Backupo .env $envBackupFile = storage_path("backups/tmp/storage/env.backup"); $envSourceFile = app()->environmentFilePath(); $command = "cp " . $envSourceFile . " " . $envBackupFile; exec($command, $output); Log::info('Backup .env'); //Clear previouse backups from same day $command = "rm -f " . storage_path('backups') . "/" . date("Y-m-d", time()) . ".zip"; exec($command, $output); Log::info('Clean previous backup'); foreach (['database' => $db_backup_path, 'storage' => $fs_backup_path] as $filename => $backupPath) { $zippedFilePath = storage_path('backups/' . date("Y-m-d", time()) . '_' . $filename . ".zip"); if (File::exists($zippedFilePath)) { $command = "rm -r -f " . $zippedFilePath; exec($command, $output); Log::Info('Clean Old Backup File' . $zippedFilePath); Log::Debug($output); } $command = "cd ".$backupPath."; zip -rm ".$zippedFilePath." ./*" ; exec($command, $output); Log::info($backupPath . '=>' . $zippedFilePath); $command = "md5sum ". $zippedFilePath; exec($command, $output); Log::info('Zipping hash'); $charSet = preg_replace(array('/\s{2,}/', '/[\t\n]/'), ' ', $output[count($output)-1]); $charSet = rtrim($charSet); $fileMD5Hash = explode(" ", $charSet)[0]; Log::debug($fileMD5Hash); Log::info($backupPath . '=>'.$zippedFilePath.'=>' .$fileMD5Hash); } if (!empty(env('APP_ADMIN'))) { Mail::raw(__('Backup Run successfully'), function ($message) { $message->to('vasek@steelants.cz')->subject(_('Backup Run successfully ') . env('APP_NAME')); }); Log::info('Sending Notification'); } } private function execShellCommand($command, &$output) { $output = $null; exec($command, $output); Log::debug($output); } }