Skip to content

Commit

Permalink
Fix issue where local backups were included in new backups (#1486)
Browse files Browse the repository at this point in the history
* test: add failing test

add test that proves the bug

* fix: issue where previous local backups were included in future backups

alter filesystemType check to look for new flysystem 3's new classname
fix usage of non-existent method getAdapter in map
  • Loading branch information
ashleyshenton authored Feb 13, 2022
1 parent a571504 commit 2cd2b4f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Tasks/Backup/BackupJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
18 changes: 18 additions & 0 deletions tests/Commands/BackupCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

0 comments on commit 2cd2b4f

Please sign in to comment.