diff --git a/.gitignore b/.gitignore index 8a0ab32..e69db04 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ /public/vendor /storage/*.key /storage/pail +/storage/app/backup /vendor .env .env.backup diff --git a/app/Console/Commands/BackupCron.php b/app/Console/Commands/BackupCron.php new file mode 100644 index 0000000..74637f1 --- /dev/null +++ b/app/Console/Commands/BackupCron.php @@ -0,0 +1,45 @@ + %s"', + env('DB_USERNAME'), + env('DB_PASSWORD'), + env('DB_DATABASE'), + $containerPath + ); + exec($dumpCommand, $output, $returnCode); + + // Copiar del contenedor al host + $copyCommand = sprintf( + 'docker cp repuve-backend-v1-mysql-1:%s %s', + $containerPath, + $hostPath + ); + exec($copyCommand); + + // Limpiar archivo temporal del contenedor + exec("docker exec repuve-backend-v1-mysql-1 rm " . $containerPath); + + $this->info('Backup creado: ' . $filename); + } +} diff --git a/routes/console.php b/routes/console.php index 0b326d0..3cf2f75 100644 --- a/routes/console.php +++ b/routes/console.php @@ -8,3 +8,4 @@ } Schedule::call(new DeleteResetPasswords)->hourly(); +Schedule::command('backup:cron')->dailyAt('00:00');