From ffb41ed31ee3d5293973ff9a16c9824e66e87119 Mon Sep 17 00:00:00 2001 From: Michal Borychowski <807297+boryn@users.noreply.github.com> Date: Mon, 2 Oct 2023 06:50:55 +0200 Subject: [PATCH] added timestamp to database dump file --- config/backup.php | 5 +++++ src/Tasks/Backup/BackupJob.php | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/config/backup.php b/config/backup.php index 8d33fe4a..1d4b6772 100644 --- a/config/backup.php +++ b/config/backup.php @@ -97,6 +97,11 @@ */ 'database_dump_compressor' => null, + /* + * If specified, the database dumped file name will contain a timestamp (e.g.: 'Y-m-d-H-i-s'). + */ + 'database_dump_file_timestamp_format' => null, + /* * The file extension used for the database dump files. * diff --git a/src/Tasks/Backup/BackupJob.php b/src/Tasks/Backup/BackupJob.php index 19dec5f2..54fe3fe0 100644 --- a/src/Tasks/Backup/BackupJob.php +++ b/src/Tasks/Backup/BackupJob.php @@ -256,7 +256,12 @@ protected function dumpDatabases(): array $dbName = $key . '-database'; } - $fileName = "{$dbType}-{$dbName}.{$this->getExtension($dbDumper)}"; + $timeStamp = ''; + if ($timeStampFormat = config('backup.backup.database_dump_file_timestamp_format')) { + $timeStamp = '-' . Carbon::now()->format($timeStampFormat); + } + + $fileName = "{$dbType}-{$dbName}{$timeStamp}.{$this->getExtension($dbDumper)}"; if (config('backup.backup.gzip_database_dump')) { $dbDumper->useCompressor(new GzipCompressor());