From 6af33e4503af399a27958a87d65f6288699f5eb7 Mon Sep 17 00:00:00 2001 From: Juan Felipe Zapata Moreno Date: Wed, 3 Dec 2025 13:09:47 -0600 Subject: [PATCH] =?UTF-8?q?ADD:=20Se=20implement=C3=B3=20el=20comando=20pa?= =?UTF-8?q?ra=20realizar=20respaldos=20autom=C3=A1ticos=20de=20la=20base?= =?UTF-8?q?=20de=20datos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + app/Console/Commands/BackupCron.php | 45 +++++++++++++++++++++++++++++ routes/console.php | 1 + 3 files changed, 47 insertions(+) create mode 100644 app/Console/Commands/BackupCron.php 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');