diff --git a/src/Tasks/Backup/BackupJob.php b/src/Tasks/Backup/BackupJob.php index 4f286ffe..20f810ce 100644 --- a/src/Tasks/Backup/BackupJob.php +++ b/src/Tasks/Backup/BackupJob.php @@ -208,9 +208,9 @@ public function filesToBeBackedUp(): Generator protected function directoriesUsedByBackupJob(): array { return $this->backupDestinations - ->filter(fn (BackupDestination $backupDestination) => $backupDestination->filesystemType() === 'local') + ->filter(fn (BackupDestination $backupDestination) => $backupDestination->filesystemType() === 'localfilesystemadapter') ->map( - fn (BackupDestination $backupDestination) => $backupDestination->disk()->getDriver()->getAdapter()->applyPathPrefix('') . $backupDestination->backupName() + fn (BackupDestination $backupDestination) => $backupDestination->disk()->path('') . $backupDestination->backupName() ) ->each(fn (string $backupDestinationDirectory) => $this->fileSelection->excludeFilesFrom($backupDestinationDirectory)) ->push($this->temporaryDirectory->path()) diff --git a/tests/Commands/BackupCommandTest.php b/tests/Commands/BackupCommandTest.php index 08d1f03d..51613d3f 100644 --- a/tests/Commands/BackupCommandTest.php +++ b/tests/Commands/BackupCommandTest.php @@ -393,4 +393,22 @@ public function it_will_encrypt_backup_when_notifications_are_disabled() Event::assertNotDispatched(BackupZipWasCreated::class); } + + /** @test */ + public function it_excludes_the_previous_local_backups_from_the_backup() + { + $this->date = Carbon::create('2016', 1, 1, 20, 1, 1); + Carbon::setTestNow($this->date); + $this->expectedZipPath = 'mysite/2016-01-01-20-01-01.zip'; + + $this->artisan('backup:run --only-files')->assertExitCode(0); + + $this->date = Carbon::create('2016', 1, 1, 21, 1, 1); + Carbon::setTestNow($this->date); + $this->expectedZipPath = 'mysite/2016-01-01-21-01-01.zip'; + + $this->artisan('backup:run --only-files')->assertExitCode(0); + + $this->assertFileDoesntExistsInZip('local', $this->expectedZipPath, '2016-01-01-20-01-01.zip'); + } }