Hy, I encountered a problem where I have no Idea where to start searching for the error.
We Backup only to s3
which works fine and run the following commands via cron:
$schedule->command('backup:run --only-db')->hourlyAt('0');
$schedule->command('backup:monitor')->hourlyAt('15');
$schedule->command('backup:clean')->dailyAt('0:30');
But I get the following exception every hour, and I don't know where I should start looking for the error. When I login via SSH and have a look what's in the folder I get an empty one.
Exception message: rmdir(/.../storage/app/laravel-backup/temp): Directory not empty
We have the newest versions of laravel and laravel-backup installed. Our config file looks like this:
<?php
return [
'backup' => [
/*
* The name of this application. You can use this name to monitor
* the backups.
*/
'name' => env('APP_URL'),
'source' => [
'files' => [
/*
* The list of directories and files that will be included in the backup.
*/
'include' => [
base_path(),
],
/*
* These directories and files will be excluded from the backup.
*
* Directories used by the backup process will automatically be excluded.
*/
'exclude' => [
base_path('vendor'),
base_path('node_modules'),
],
/*
* Determines if symlinks should be followed.
*/
'followLinks' => false,
],
/*
* The names of the connections to the databases that should be backed up
* Only MySQL and PostgreSQL databases are supported.
*/
'databases' => [
'mysql',
],
],
'destination' => [
/*
* The disk names on which the backups will be stored.
*/
'disks' => [
's3',
],
],
],
/*
* You can get notified when specific events occur. Out of the box you can use 'mail' and 'slack'.
* For Slack you need to install guzzlehttp/guzzle.
*
* You can also use your own notification classes, just make sure the class is named after one of
* the `Spatie\Backup\Events` classes.
*/
'notifications' => [
'notifications' => [
\Spatie\Backup\Notifications\Notifications\BackupHasFailed::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\UnhealthyBackupWasFound::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\CleanupHasFailed::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\BackupWasSuccessful::class => [],
\Spatie\Backup\Notifications\Notifications\HealthyBackupWasFound::class => [],
\Spatie\Backup\Notifications\Notifications\CleanupWasSuccessful::class => [],
],
/*
* Here you can specify the notifiable to which the notifications should be sent. The default
* notifiable will use the variables specified in this config file.
*/
'notifiable' => \Spatie\Backup\Notifications\Notifiable::class,
'mail' => [
'to' => '.....',
],
'slack' => [
'webhook_url' => '',
],
],
/*
* Here you can specify which backups should be monitored.
* If a backup does not meet the specified requirements the
* UnHealthyBackupWasFound event will be fired.
*/
'monitorBackups' => [
[
'name' => env('APP_URL'),
'disks' => ['s3'],
'newestBackupsShouldNotBeOlderThanDays' => 1,
'storageUsedMayNotBeHigherThanMegabytes' => 500000,
],
/*
[
'name' => 'name of the second app',
'disks' => ['local', 's3'],
'newestBackupsShouldNotBeOlderThanDays' => 1,
'storageUsedMayNotBeHigherThanMegabytes' => 5000,
],
*/
],
'cleanup' => [
/*
* The strategy that will be used to cleanup old backups. The default strategy
* will keep all backups for a certain amount of days. After that period only
* a daily backup will be kept. After that period only weekly backups will
* be kept and so on.
*
* No matter how you configure it the default strategy will never
* delete the newest backup.
*/
'strategy' => \Spatie\Backup\Tasks\Cleanup\Strategies\DefaultStrategy::class,
'defaultStrategy' => [
/*
* The number of days for which backups must be kept.
*/
'keepAllBackupsForDays' => 14,
/*
* The number of days for which daily backups must be kept.
*/
'keepDailyBackupsForDays' => 31,
/*
* The number of weeks for which one weekly backup must be kept.
*/
'keepWeeklyBackupsForWeeks' => 8,
/*
* The number of months for which one monthly backup must be kept.
*/
'keepMonthlyBackupsForMonths' => 4,
/*
* The number of years for which one yearly backup must be kept.
*/
'keepYearlyBackupsForYears' => 2,
/*
* After cleaning up the backups remove the oldest backup until
* this amount of megabytes has been reached.
*/
'deleteOldestBackupsWhenUsingMoreMegabytesThan' => 500000,
],
],
];
And finally here's the detailed exception:
Important: An error occurred while backing up GH - saturn
Exception message: rmdir(/.../storage/app/laravel-backup/temp): Directory not empty
Exception trace: #0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'rmdir(/...', '/...', 178, Array)
#1 /.../vendor/spatie/temporary-directory/src/TemporaryDirectory.php(178): rmdir('/...')
#2 /.../vendor/spatie/temporary-directory/src/TemporaryDirectory.php(110): Spatie\TemporaryDirectory\TemporaryDirectory->deleteDirectory('/...')
#3 /.../vendor/spatie/laravel-backup/src/Tasks/Backup/BackupJob.php(132): Spatie\TemporaryDirectory\TemporaryDirectory->delete()
#4 /.../vendor/spatie/laravel-backup/src/Commands/BackupCommand.php(43): Spatie\Backup\Tasks\Backup\BackupJob->run()
#5 [internal function]: Spatie\Backup\Commands\BackupCommand->handle()
#6 /.../vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(28): call_user_func_array(Array, Array)
#7 /.../vendor/laravel/framework/src/Illuminate/Support/helpers.php(912): Illuminate\Container\BoundMethod::Illuminate\Container{closure}()
#8 /.../vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(86): value(Object(Closure))
#9 /.../vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(30): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure)) #
10 /.../vendor/laravel/framework/src/Illuminate/Container/Container.php(524): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#11 /.../vendor/laravel/framework/src/Illuminate/Console/Command.php(182): Illuminate\Container\Container->call(Array)
#12 /.../vendor/symfony/console/Command/Command.php(262): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#13 /.../vendor/laravel/framework/src/Illuminate/Console/Command.php(167): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#14 /.../vendor/spatie/laravel-backup/src/Commands/BaseCommand.php(22): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /.../vendor/symfony/console/Application.php(826): Spatie\Backup\Commands\BaseCommand->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /.../vendor/symfony/console/Application.php(189): Symfony\Component\Console\Application->doRunCommand(Object(Spatie\Backup\Commands\BackupCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /.../vendor/symfony/console/Application.php(120): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 /.../vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(123): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 /.../artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 {main}