snipe / snipe-it

A free open source IT asset/license management system
https://snipeitapp.com
GNU Affero General Public License v3.0
11.09k stars 3.18k forks source link

Manual backup fails on Windows (Invalid or uninitialized Zip object) #13027

Open drewbino-rcg opened 1 year ago

drewbino-rcg commented 1 year ago

Debug mode

Describe the bug

When attempting to generate a manual backup through the Admin area, a "500 Server Error" appears.

In debug mode, the error is:

ValueError: Invalid or uninitialized Zip object

See additional context below for possible solution.

Reproduction steps

On a Snipe IT installation running on Windows:

  1. Click the settings gear in the top-right corner.
  2. Click Backups.
  3. Click Generate Backup.
  4. Error appears.

Expected behavior

The page should refresh and show that a new backup file has been generated.

Screenshots

No response

Snipe-IT Version

v6.1.1-pre - build 10653 (master)

Operating System

Windows

Web Server

IIS

PHP Version

8.0.28

Operating System

Windows

Browser

MS Edge

Version

113

Device

No response

Operating System

No response

Browser

No response

Version

No response

Error messages

ValueError: Invalid or uninitialized Zip object in C:\Snipe-IT\vendor\spatie\laravel-backup\src\Tasks\Backup\Zip.php:114
Stack trace:
#0 C:\Snipe-IT\vendor\spatie\laravel-backup\src\Tasks\Backup\Zip.php(114): ZipArchive->addEmptyDir()
#1 C:\Snipe-IT\vendor\spatie\laravel-backup\src\Tasks\Backup\Zip.php(33): Spatie\Backup\Tasks\Backup\Zip->add()
#2 C:\Snipe-IT\vendor\spatie\laravel-backup\src\Tasks\Backup\BackupJob.php(213): Spatie\Backup\Tasks\Backup\Zip::createForManifest()
#3 C:\Snipe-IT\vendor\spatie\laravel-backup\src\Tasks\Backup\BackupJob.php(153): Spatie\Backup\Tasks\Backup\BackupJob->createZipContainingEveryFileInManifest()
#4 C:\Snipe-IT\vendor\spatie\laravel-backup\src\Commands\BackupCommand.php(56): Spatie\Backup\Tasks\Backup\BackupJob->run()
#5 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(36): Spatie\Backup\Commands\BackupCommand->handle()
#6 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Container\Util.php(40): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#7 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#8 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod()
#9 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Container\Container.php(653): Illuminate\Container\BoundMethod::call()
#10 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Console\Command.php(136): Illuminate\Container\Container->call()
#11 C:\Snipe-IT\vendor\symfony\console\Command\Command.php(298): Illuminate\Console\Command->execute()
#12 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Console\Command.php(121): Symfony\Component\Console\Command\Command->run()
#13 C:\Snipe-IT\vendor\spatie\laravel-backup\src\Commands\BaseCommand.php(16): Illuminate\Console\Command->run()
#14 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Console\Concerns\CallsCommands.php(68): Spatie\Backup\Commands\BaseCommand->run()
#15 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Console\Concerns\CallsCommands.php(28): Illuminate\Console\Command->runCommand()
#16 C:\Snipe-IT\app\Console\Commands\SystemBackup.php(48): Illuminate\Console\Command->call()
#17 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(36): App\Console\Commands\SystemBackup->handle()
#18 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Container\Util.php(40): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#19 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#20 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod()
#21 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Container\Container.php(653): Illuminate\Container\BoundMethod::call()
#22 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Console\Command.php(136): Illuminate\Container\Container->call()
#23 C:\Snipe-IT\vendor\symfony\console\Command\Command.php(298): Illuminate\Console\Command->execute()
#24 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Console\Command.php(121): Symfony\Component\Console\Command\Command->run()
#25 C:\Snipe-IT\vendor\symfony\console\Application.php(1024): Illuminate\Console\Command->run()
#26 C:\Snipe-IT\vendor\symfony\console\Application.php(299): Symfony\Component\Console\Application->doRunCommand()
#27 C:\Snipe-IT\vendor\symfony\console\Application.php(171): Symfony\Component\Console\Application->doRun()
#28 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Console\Application.php(94): Symfony\Component\Console\Application->run()
#29 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Console\Application.php(186): Illuminate\Console\Application->run()
#30 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(263): Illuminate\Console\Application->call()
#31 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php(261): Illuminate\Foundation\Console\Kernel->call()
#32 C:\Snipe-IT\app\Http\Controllers\SettingsController.php(1139): Illuminate\Support\Facades\Facade::__callStatic()
#33 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Routing\Controller.php(54): App\Http\Controllers\SettingsController->postBackups()
#34 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction()
#35 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Routing\Route.php(262): Illuminate\Routing\ControllerDispatcher->dispatch()
#36 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Routing\Route.php(205): Illuminate\Routing\Route->runController()
#37 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Routing\Router.php(721): Illuminate\Routing\Route->run()
#38 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(128): Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#39 C:\Snipe-IT\app\Http\Middleware\CheckPermissions.php(24): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#40 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): App\Http\Middleware\CheckPermissions->handle()
#41 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Session\Middleware\AuthenticateSession.php(58): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#42 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Session\Middleware\AuthenticateSession->handle()
#43 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Auth\Middleware\Authenticate.php(44): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#44 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Auth\Middleware\Authenticate->handle()
#45 C:\Snipe-IT\app\Http\Middleware\AssetCountForSidebar.php(62): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#46 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): App\Http\Middleware\AssetCountForSidebar->handle()
#47 C:\Snipe-IT\vendor\laravel\passport\src\Http\Middleware\CreateFreshApiToken.php(50): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#48 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Laravel\Passport\Http\Middleware\CreateFreshApiToken->handle()
#49 C:\Snipe-IT\app\Http\Middleware\CheckForTwoFactor.php(59): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#50 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): App\Http\Middleware\CheckForTwoFactor->handle()
#51 C:\Snipe-IT\app\Http\Middleware\CheckUserIsActivated.php(47): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#52 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): App\Http\Middleware\CheckUserIsActivated->handle()
#53 C:\Snipe-IT\app\Http\Middleware\CheckLocale.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#54 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): App\Http\Middleware\CheckLocale->handle()
#55 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php(78): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#56 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle()
#57 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#58 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle()
#59 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\EncryptCookies.php(67): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#60 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Cookie\Middleware\EncryptCookies->handle()
#61 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#62 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Routing\Router.php(723): Illuminate\Pipeline\Pipeline->then()
#63 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Routing\Router.php(698): Illuminate\Routing\Router->runRouteWithinStack()
#64 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Routing\Router.php(662): Illuminate\Routing\Router->runRoute()
#65 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Routing\Router.php(651): Illuminate\Routing\Router->dispatchToRoute()
#66 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(167): Illuminate\Routing\Router->dispatch()
#67 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(128): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}()
#68 C:\Snipe-IT\vendor\livewire\livewire\src\DisableBrowserCache.php(19): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#69 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Livewire\DisableBrowserCache->handle()
#70 C:\Snipe-IT\vendor\barryvdh\laravel-debugbar\src\Middleware\InjectDebugbar.php(66): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#71 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Barryvdh\Debugbar\Middleware\InjectDebugbar->handle()
#72 C:\Snipe-IT\vendor\fruitcake\laravel-cors\src\HandleCors.php(38): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#73 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Fruitcake\Cors\HandleCors->handle()
#74 C:\Snipe-IT\app\Http\Middleware\PreventBackHistory.php(23): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#75 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): App\Http\Middleware\PreventBackHistory->handle()
#76 C:\Snipe-IT\app\Http\Middleware\SecurityHeaders.php(26): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#77 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): App\Http\Middleware\SecurityHeaders->handle()
#78 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#79 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull.php(31): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#80 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull->handle()
#81 C:\Snipe-IT\app\Http\Middleware\CheckForDebug.php(25): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#82 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): App\Http\Middleware\CheckForDebug->handle()
#83 C:\Snipe-IT\app\Http\Middleware\CheckForSetup.php(25): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#84 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): App\Http\Middleware\CheckForSetup->handle()
#85 C:\Snipe-IT\vendor\fideloper\proxy\src\TrustProxies.php(57): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#86 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Fideloper\Proxy\TrustProxies->handle()
#87 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\View\Middleware\ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#88 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\View\Middleware\ShareErrorsFromSession->handle()
#89 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php(121): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#90 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php(64): Illuminate\Session\Middleware\StartSession->handleStatefulRequest()
#91 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Session\Middleware\StartSession->handle()
#92 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance.php(86): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#93 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle()
#94 C:\Snipe-IT\app\Http\Middleware\NoSessionStore.php(28): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#95 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): App\Http\Middleware\NoSessionStore->handle()
#96 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#97 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(142): Illuminate\Pipeline\Pipeline->then()
#98 C:\Snipe-IT\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(111): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter()
#99 C:\Snipe-IT\public\index.php(52): Illuminate\Foundation\Http\Kernel->handle()
#100 {main}

Additional context

I followed the stack trace back and I think I found the issue:

Line 1139 of app/Http/Controllers/SettingsController.php is specifying a datetime format for the backup filename that contains colons (date('Y-m-d-H:i:s')), which are not allowed in Windows filenames.

https://github.com/snipe/snipe-it/blob/869d195b35f100a9022b72a78f5b27cde7d800ac/app/Http/Controllers/SettingsController.php#LL1139C13-L1139C13

Replacing the colons with hyphens fixes the issue.

welcome[bot] commented 1 year ago

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.