diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..dec63d5 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,7 @@ +- LaravelBackup Version: #.#.# +- Laravel Version: #.#.# +- PHP Version: #.#.# + +### Description: + +### Steps To Reproduce: diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 42c4908..fbf91bd 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -9,7 +9,7 @@ jobs: strategy: fail-fast: true matrix: - php: [7.2, 7.3, 7.4] + php: [7.3, 7.4] dependency-version: [prefer-lowest, prefer-stable] name: PHP ${{ matrix.php }} - ${{ matrix.dependency-version }} @@ -27,7 +27,7 @@ jobs: uses: actions/cache@v2 with: path: ~/.composer/cache/files - key: dependencies-laravel-7-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} + key: dependencies-laravel-8-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 5192edd..f37ce73 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -21,7 +21,7 @@ checks: tools: external_code_coverage: timeout: 600 - runs: 6 + runs: 4 php_code_sniffer: enabled: true config: diff --git a/composer.json b/composer.json index 8784f27..e79706c 100644 --- a/composer.json +++ b/composer.json @@ -14,18 +14,18 @@ "type": "library", "license": "MIT", "require": { - "php": "^7.2.5", - "ext-json": "*", - "ext-zip": "*", - "arcanedev/support": "^7.0", - "league/flysystem": "^1.0.49" + "php": "^7.3", + "ext-json": "*", + "ext-zip": "*", + "arcanedev/support": "^8.0", + "league/flysystem": "^1.0.49" }, "require-dev": { - "laravel/slack-notification-channel": "^2.0", - "league/flysystem-aws-s3-v3": "^1.0.1", - "mockery/mockery": "^1.3.1", - "orchestra/testbench": "^5.0", - "phpunit/phpunit": "^8.5|^9.0" + "laravel/slack-notification-channel": "^2.2", + "league/flysystem-aws-s3-v3": "^1.0.1", + "mockery/mockery": "^1.3.1", + "orchestra/testbench": "^6.0", + "phpunit/phpunit": "^9.3" }, "autoload": { "psr-4": { @@ -37,7 +37,14 @@ "Arcanedev\\LaravelBackup\\Tests\\": "tests/" } }, + "scripts": { + "test": "phpunit", + "coverage": "phpunit --coverage-html build/coverage/html" + }, "extra": { + "branch-alias": { + "dev-develop": "2.x-dev" + }, "laravel": { "providers": [ "Arcanedev\\LaravelBackup\\BackupServiceProvider", @@ -45,6 +52,9 @@ ] } }, + "config": { + "sort-packages": true + }, "minimum-stability": "dev", "prefer-stable": true } diff --git a/config/backup.php b/config/backup.php index 1724325..821995a 100644 --- a/config/backup.php +++ b/config/backup.php @@ -7,6 +7,9 @@ | ----------------------------------------------------------------- */ + /* + * The name of this application. You can use this name to monitor the backups. + */ 'name' => env('APP_NAME', 'laravel-backup'), /* ----------------------------------------------------------------- @@ -16,8 +19,10 @@ 'destination' => [ + // The filename prefix used for the backup zip file. 'filename-prefix' => '', + // The disk names on which the backups will be stored. 'disks' => [ 'local', ], @@ -32,24 +37,82 @@ 'backup' => [ '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. 'follow-links' => false, + + // Determines if it should avoid unreadable folders. + 'ignore-unreadable-directories' => false, + ], + /* + * The names of the connections to the databases that should be backed up + * MySQL, PostgreSQL, SQLite and Mongo databases are supported. + * + * The content of the database dump may be customized for each connection + * by adding a 'dump' key to the connection settings in config/database.php. + * E.g. + * 'mysql' => [ + * ... + * 'dump' => [ + * 'excludeTables' => [ + * 'table_to_exclude_from_backup', + * 'another_table_to_exclude' + * ] + * ], + * ], + * + * If you are using only InnoDB tables on a MySQL server, you can + * also supply the useSingleTransaction option to avoid table locking. + * + * E.g. + * 'mysql' => [ + * ... + * 'dump' => [ + * 'useSingleTransaction' => true, + * ], + * ], + * + * For a complete list of available customization options, see https://github.com/spatie/db-dumper + */ 'databases' => [ 'mysql', ], + ], + /* + * The database dump can be compressed to decrease disk space usage. + * + * Out of the box LaravelBackup supplies: + * Arcanedev\LaravelBackup\Database\Compressors\GzipCompressor::class + * + * You can also use a custom compressor by implementing the contract: + * Arcanedev\LaravelBackup\Database\Contracts\Compressor + * + * If you do not want any compressor at all, set it to `null`. + */ + 'db-dump-compressor' => null, + + // The directory where the temporary files will be stored. 'temporary-directory' => storage_path('app/_backup-temp'), 'tasks' => [ @@ -68,41 +131,36 @@ | ----------------------------------------------------------------- */ + /* + * 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. + */ 'cleanup' => [ 'strategy' => [ 'default' => Arcanedev\LaravelBackup\Actions\Cleanup\Strategies\DefaultStrategy::class, 'keep-backups' => [ - /** - * The number of days for which backups must be kept. - */ + // The number of days for which backups must be kept. 'all' => 7, - /** - * The number of days for which daily backups must be kept. - */ + // The number of days for which daily backups must be kept. 'daily' => 16, - /** - * The number of weeks for which one weekly backup must be kept. - */ + // The number of weeks for which one weekly backup must be kept. 'weekly' => 8, - /** - * The number of months for which one monthly backup must be kept. - */ + // The number of months for which one monthly backup must be kept. 'monthly' => 4, - /** - * The number of years for which one yearly backup must be kept. - */ + // The number of years for which one yearly backup must be kept. 'yearly' => 2, ], - /* - * After cleaning up the backups remove the oldest backup until this amount of megabytes has been reached. - */ + // After cleaning up the backups remove the oldest backup until this amount of megabytes has been reached. 'delete-backups' => [ 'oldest-when-size-reach' => 5000, ], @@ -120,6 +178,10 @@ | ----------------------------------------------------------------- */ + /* + * Here you can specify which backups should be monitored. + * If a backup does not meet the specified requirements the UnhealthyBackupsWasFound event will be fired. + */ 'monitor' => [ 'destinations' => [ @@ -155,6 +217,14 @@ | ----------------------------------------------------------------- */ + /* + * You can get notified when specific events occur. Out of the box you can use 'mail' and 'slack'. + * + * For 'slack' you need to install 'laravel/slack-notification-channel'. + * + * You can also use your own notification classes, just make sure the class is named after one of + * the `Arcanedev\LaravelBackup\Events` classes. + */ 'notifications' => [ 'supported' => [ @@ -176,6 +246,7 @@ 'mail' => [ 'to' => 'your@example.com', + 'from' => [ 'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'), 'name' => env('MAIL_FROM_NAME', 'Example'), @@ -185,7 +256,7 @@ 'slack' => [ 'webhook_url' => '', - /* If this is set to null the default channel of the webhook will be used. */ + // If this is set to null the default channel of the webhook will be used. 'channel' => null, 'username' => null, 'icon' => null, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 415b7dc..81e3f78 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,24 +1,24 @@ - +> ./tests - - + + ./src - - + + + + + + + diff --git a/src/Actions/Action.php b/src/Actions/Action.php index 7ed3210..1967ecb 100644 --- a/src/Actions/Action.php +++ b/src/Actions/Action.php @@ -9,7 +9,6 @@ /** * Class Action * - * @package Arcanedev\LaravelBackup\Actions * @author ARCANEDEV */ abstract class Action extends Pipeline diff --git a/src/Actions/Backup/BackupAction.php b/src/Actions/Backup/BackupAction.php index b1ee92e..8fd137d 100644 --- a/src/Actions/Backup/BackupAction.php +++ b/src/Actions/Backup/BackupAction.php @@ -11,7 +11,6 @@ /** * Class BackupAction * - * @package Arcanedev\LaravelBackup\Actions\Backup * @author ARCANEDEV */ class BackupAction extends Action diff --git a/src/Actions/Backup/BackupPassable.php b/src/Actions/Backup/BackupPassable.php index f944161..bbaf02b 100644 --- a/src/Actions/Backup/BackupPassable.php +++ b/src/Actions/Backup/BackupPassable.php @@ -11,7 +11,6 @@ /** * Class BackupPassable * - * @package Arcanedev\LaravelBackup\Actions\Backup * @author ARCANEDEV */ class BackupPassable extends Passable diff --git a/src/Actions/Backup/Tasks/CheckBackupDestinations.php b/src/Actions/Backup/Tasks/CheckBackupDestinations.php index 8bd9d0f..9485fd8 100644 --- a/src/Actions/Backup/Tasks/CheckBackupDestinations.php +++ b/src/Actions/Backup/Tasks/CheckBackupDestinations.php @@ -11,7 +11,6 @@ /** * Class CheckBackupDestinations * - * @package Arcanedev\LaravelBackup\Actions\Backup\Tasks * @author ARCANEDEV */ class CheckBackupDestinations implements TaskInterface diff --git a/src/Actions/Backup/Tasks/CheckOptions.php b/src/Actions/Backup/Tasks/CheckOptions.php index 00ebbd3..4cf0449 100644 --- a/src/Actions/Backup/Tasks/CheckOptions.php +++ b/src/Actions/Backup/Tasks/CheckOptions.php @@ -12,7 +12,6 @@ /** * Class CheckOptions * - * @package Arcanedev\LaravelBackup\Actions\Backup\Tasks * @author ARCANEDEV */ class CheckOptions implements TaskInterface diff --git a/src/Actions/Backup/Tasks/CreateBackupFile.php b/src/Actions/Backup/Tasks/CreateBackupFile.php index 6aa81bb..4123f0e 100644 --- a/src/Actions/Backup/Tasks/CreateBackupFile.php +++ b/src/Actions/Backup/Tasks/CreateBackupFile.php @@ -5,7 +5,7 @@ namespace Arcanedev\LaravelBackup\Actions\Backup\Tasks; use Arcanedev\LaravelBackup\Actions\TaskInterface; -use Arcanedev\LaravelBackup\Entities\Manifest; +use Arcanedev\LaravelBackup\Entities\{Backup, Manifest}; use Arcanedev\LaravelBackup\Events\BackupZipWasCreated; use Arcanedev\LaravelBackup\Helpers\Zip; use Closure; @@ -14,7 +14,6 @@ /** * Class CreateBackupFile * - * @package Arcanedev\LaravelBackup\Actions\Backup\Tasks * @author ARCANEDEV */ class CreateBackupFile implements TaskInterface @@ -77,6 +76,6 @@ protected static function createZipFile(Manifest $manifest, string $path): Zip */ protected static function getFilename(): string { - return Carbon::now()->format('Ymd-His').'.zip'; + return Carbon::now()->format(Backup::FILENAME_FORMAT); } } diff --git a/src/Actions/Backup/Tasks/CreateTemporaryDirectory.php b/src/Actions/Backup/Tasks/CreateTemporaryDirectory.php index 825bde0..a7a7909 100644 --- a/src/Actions/Backup/Tasks/CreateTemporaryDirectory.php +++ b/src/Actions/Backup/Tasks/CreateTemporaryDirectory.php @@ -11,7 +11,6 @@ /** * Class CreateTemporaryDirectory * - * @package Arcanedev\LaravelBackup\Tasks\RunBackup * @author ARCANEDEV */ class CreateTemporaryDirectory implements TaskInterface diff --git a/src/Actions/Backup/Tasks/MoveBackupToDisks.php b/src/Actions/Backup/Tasks/MoveBackupToDisks.php index 39e64b8..fddcd43 100644 --- a/src/Actions/Backup/Tasks/MoveBackupToDisks.php +++ b/src/Actions/Backup/Tasks/MoveBackupToDisks.php @@ -11,7 +11,6 @@ /** * Class MoveBackupToDisks * - * @package Arcanedev\LaravelBackup\Actions\Backup\Tasks * @author ARCANEDEV */ class MoveBackupToDisks implements TaskInterface diff --git a/src/Actions/Backup/Tasks/PrepareFilesToBackup.php b/src/Actions/Backup/Tasks/PrepareFilesToBackup.php index 19b2bbb..29bfa3a 100644 --- a/src/Actions/Backup/Tasks/PrepareFilesToBackup.php +++ b/src/Actions/Backup/Tasks/PrepareFilesToBackup.php @@ -15,7 +15,6 @@ /** * Class PrepareFilesToBackup * - * @package Arcanedev\LaravelBackup\Actions\Backup\Tasks * @author ARCANEDEV */ class PrepareFilesToBackup implements TaskInterface @@ -114,6 +113,7 @@ protected function selectedFiles(BackupPassable $passable): array ->include($files['include']) ->exclude($files['exclude']) ->shouldFollowLinks($files['follow-links'] ?: false) + ->shouldIgnoreUnreadableDirs($files['ignore-unreadable-directories'] ?: false) ->selectedAsArray(); } diff --git a/src/Actions/Cleanup/CleanAction.php b/src/Actions/Cleanup/CleanAction.php index a5d69c2..8f92c35 100644 --- a/src/Actions/Cleanup/CleanAction.php +++ b/src/Actions/Cleanup/CleanAction.php @@ -11,7 +11,6 @@ /** * Class CleanAction * - * @package Arcanedev\LaravelBackup\Actions\Cleanup * @author ARCANEDEV */ class CleanAction extends Action diff --git a/src/Actions/Cleanup/CleanupPassable.php b/src/Actions/Cleanup/CleanupPassable.php index 9d09ffb..4c1223e 100644 --- a/src/Actions/Cleanup/CleanupPassable.php +++ b/src/Actions/Cleanup/CleanupPassable.php @@ -9,9 +9,8 @@ use Illuminate\Support\Collection; /** - * Class CleanPassable + * Class CleanupPassable * - * @package Arcanedev\LaravelBackup\Actions\Cleanup * @author ARCANEDEV */ class CleanupPassable extends Passable diff --git a/src/Actions/Cleanup/Strategies/CleanupStrategy.php b/src/Actions/Cleanup/Strategies/CleanupStrategy.php index c45af9e..6daf5fc 100644 --- a/src/Actions/Cleanup/Strategies/CleanupStrategy.php +++ b/src/Actions/Cleanup/Strategies/CleanupStrategy.php @@ -8,10 +8,9 @@ use Illuminate\Support\Collection; /** - * Interface CleanupStrategy + * Interface CleanupStrategy * - * @package Arcanedev\LaravelBackup\Actions\Cleanup\Strategies - * @author ARCANEDEV + * @author ARCANEDEV */ interface CleanupStrategy { diff --git a/src/Actions/Cleanup/Strategies/DefaultStrategy.php b/src/Actions/Cleanup/Strategies/DefaultStrategy.php index 391ea4a..57f80a8 100644 --- a/src/Actions/Cleanup/Strategies/DefaultStrategy.php +++ b/src/Actions/Cleanup/Strategies/DefaultStrategy.php @@ -10,7 +10,6 @@ /** * Class DefaultStrategy * - * @package Arcanedev\LaravelBackup\Actions\Cleanup\Strategies * @author ARCANEDEV */ class DefaultStrategy implements CleanupStrategy diff --git a/src/Actions/Cleanup/Tasks/ApplyCleanupStrategy.php b/src/Actions/Cleanup/Tasks/ApplyCleanupStrategy.php index b312651..69c9367 100644 --- a/src/Actions/Cleanup/Tasks/ApplyCleanupStrategy.php +++ b/src/Actions/Cleanup/Tasks/ApplyCleanupStrategy.php @@ -12,7 +12,6 @@ /** * Class ApplyCleanupStrategy * - * @package Arcanedev\LaravelBackup\Actions\Cleanup\Tasks * @author ARCANEDEV */ class ApplyCleanupStrategy implements TaskInterface diff --git a/src/Actions/Cleanup/Tasks/CheckBackupDestinations.php b/src/Actions/Cleanup/Tasks/CheckBackupDestinations.php index 9bc2f48..d5bdc86 100644 --- a/src/Actions/Cleanup/Tasks/CheckBackupDestinations.php +++ b/src/Actions/Cleanup/Tasks/CheckBackupDestinations.php @@ -11,7 +11,6 @@ /** * Class CheckBackupDestinations * - * @package Arcanedev\LaravelBackup\Actions\Cleanup\Tasks * @author ARCANEDEV */ class CheckBackupDestinations implements TaskInterface diff --git a/src/Actions/Monitor/HealthCheckFailure.php b/src/Actions/Monitor/HealthCheckFailure.php index 7817a65..4f272f7 100644 --- a/src/Actions/Monitor/HealthCheckFailure.php +++ b/src/Actions/Monitor/HealthCheckFailure.php @@ -11,7 +11,6 @@ /** * Class HealthCheckFailure * - * @package Arcanedev\LaravelBackup\Actions\Monitor * @author ARCANEDEV */ class HealthCheckFailure diff --git a/src/Actions/Monitor/HealthChecks/AbstractHealthCheck.php b/src/Actions/Monitor/HealthChecks/AbstractHealthCheck.php index 1785c2f..91fdc60 100644 --- a/src/Actions/Monitor/HealthChecks/AbstractHealthCheck.php +++ b/src/Actions/Monitor/HealthChecks/AbstractHealthCheck.php @@ -10,7 +10,6 @@ /** * Class AbstractHealthCheck * - * @package Arcanedev\LaravelBackup\Actions\Monitor\HealthChecks * @author ARCANEDEV */ abstract class AbstractHealthCheck implements HealthCheckable diff --git a/src/Actions/Monitor/HealthChecks/HealthCheckable.php b/src/Actions/Monitor/HealthChecks/HealthCheckable.php index 76be454..f9cb3e0 100644 --- a/src/Actions/Monitor/HealthChecks/HealthCheckable.php +++ b/src/Actions/Monitor/HealthChecks/HealthCheckable.php @@ -7,10 +7,9 @@ use Arcanedev\LaravelBackup\Entities\BackupDestination; /** - * Interface HealthCheckable + * Interface HealthCheckable * - * @package Arcanedev\LaravelBackup\Actions\Monitor\HealthChecks - * @author ARCANEDEV + * @author ARCANEDEV */ interface HealthCheckable { diff --git a/src/Actions/Monitor/HealthChecks/IsReachable.php b/src/Actions/Monitor/HealthChecks/IsReachable.php index 22dc5f1..4b52ae0 100644 --- a/src/Actions/Monitor/HealthChecks/IsReachable.php +++ b/src/Actions/Monitor/HealthChecks/IsReachable.php @@ -9,7 +9,6 @@ /** * Class IsReachable * - * @package Arcanedev\LaravelBackup\Actions\Monitor\HealthChecks * @author ARCANEDEV */ class IsReachable extends AbstractHealthCheck diff --git a/src/Actions/Monitor/HealthChecks/MaximumAgeInDays.php b/src/Actions/Monitor/HealthChecks/MaximumAgeInDays.php index 6bcf972..7861b48 100644 --- a/src/Actions/Monitor/HealthChecks/MaximumAgeInDays.php +++ b/src/Actions/Monitor/HealthChecks/MaximumAgeInDays.php @@ -4,14 +4,12 @@ namespace Arcanedev\LaravelBackup\Actions\Monitor\HealthChecks; -use Arcanedev\LaravelBackup\Entities\Backup; -use Arcanedev\LaravelBackup\Entities\BackupDestination; +use Arcanedev\LaravelBackup\Entities\{Backup, BackupDestination}; use Carbon\Carbon; /** * Class MaximumAgeInDays * - * @package Arcanedev\LaravelBackup\Actions\Monitor\HealthChecks * @author ARCANEDEV */ class MaximumAgeInDays extends AbstractHealthCheck diff --git a/src/Actions/Monitor/HealthChecks/MaximumStorageInMegabytes.php b/src/Actions/Monitor/HealthChecks/MaximumStorageInMegabytes.php index c1d32f5..5387b83 100644 --- a/src/Actions/Monitor/HealthChecks/MaximumStorageInMegabytes.php +++ b/src/Actions/Monitor/HealthChecks/MaximumStorageInMegabytes.php @@ -10,7 +10,6 @@ /** * Class MaximumStorageInMegabytes * - * @package Arcanedev\LaravelBackup\Actions\Monitor\HealthChecks * @author ARCANEDEV */ class MaximumStorageInMegabytes extends AbstractHealthCheck diff --git a/src/Actions/Monitor/MonitorAction.php b/src/Actions/Monitor/MonitorAction.php index bda4838..2c937d3 100644 --- a/src/Actions/Monitor/MonitorAction.php +++ b/src/Actions/Monitor/MonitorAction.php @@ -11,7 +11,6 @@ /** * Class MonitorAction * - * @package Arcanedev\LaravelBackup\Actions\Monitor * @author ARCANEDEV */ class MonitorAction extends Action diff --git a/src/Actions/Monitor/MonitorPassable.php b/src/Actions/Monitor/MonitorPassable.php index 0677090..6e510cb 100644 --- a/src/Actions/Monitor/MonitorPassable.php +++ b/src/Actions/Monitor/MonitorPassable.php @@ -10,7 +10,6 @@ /** * Class MonitorPassable * - * @package Arcanedev\LaravelBackup\Actions\Monitor * @author ARCANEDEV */ class MonitorPassable extends Passable diff --git a/src/Actions/Monitor/Tasks/CheckBackupsHealth.php b/src/Actions/Monitor/Tasks/CheckBackupsHealth.php index a669b9c..675adc3 100644 --- a/src/Actions/Monitor/Tasks/CheckBackupsHealth.php +++ b/src/Actions/Monitor/Tasks/CheckBackupsHealth.php @@ -12,7 +12,6 @@ /** * Class CheckBackupsHealth * - * @package Arcanedev\LaravelBackup\Actions\Monitor\Tasks * @author ARCANEDEV */ class CheckBackupsHealth implements TaskInterface diff --git a/src/Actions/Passable.php b/src/Actions/Passable.php index 6ea078f..4551ce4 100644 --- a/src/Actions/Passable.php +++ b/src/Actions/Passable.php @@ -9,7 +9,6 @@ /** * Class Passable * - * @package Arcanedev\LaravelBackup\Actions * @author ARCANEDEV */ abstract class Passable diff --git a/src/Actions/TaskInterface.php b/src/Actions/TaskInterface.php index 86f8704..a32bbb8 100644 --- a/src/Actions/TaskInterface.php +++ b/src/Actions/TaskInterface.php @@ -7,10 +7,9 @@ use Closure; /** - * Interface TaskInterface + * Interface TaskInterface * - * @package Arcanedev\LaravelBackup\Actions - * @author ARCANEDEV + * @author ARCANEDEV */ interface TaskInterface { diff --git a/src/BackupServiceProvider.php b/src/BackupServiceProvider.php index 76afe60..12af22f 100644 --- a/src/BackupServiceProvider.php +++ b/src/BackupServiceProvider.php @@ -9,7 +9,6 @@ /** * Class BackupServiceProvider * - * @package Arcanedev\LaravelBackup * @author ARCANEDEV */ class BackupServiceProvider extends PackageServiceProvider diff --git a/src/Console/CleanupBackupCommand.php b/src/Console/CleanupBackupCommand.php index 6bd4076..01f0225 100644 --- a/src/Console/CleanupBackupCommand.php +++ b/src/Console/CleanupBackupCommand.php @@ -14,7 +14,6 @@ /** * Class CleanupBackupCommand * - * @package Arcanedev\LaravelBackup\Console * @author ARCANEDEV */ class CleanupBackupCommand extends Command @@ -65,12 +64,12 @@ public function handle(CleanAction $action): int $this->comment(__('Cleanup completed!')); - return 0; + return Command::SUCCESS; } catch (Exception $e) { $this->error(__("Cleanup failed because: :message", ['message' => $e->getMessage()])); - return 1; + return Command::FAILURE; } } } diff --git a/src/Console/MonitorBackupCommand.php b/src/Console/MonitorBackupCommand.php index 8f6ad18..f4d1855 100644 --- a/src/Console/MonitorBackupCommand.php +++ b/src/Console/MonitorBackupCommand.php @@ -12,7 +12,6 @@ /** * Class MonitorBackupCommand * - * @package Arcanedev\LaravelBackup\Console * @author ARCANEDEV */ class MonitorBackupCommand extends Command @@ -61,6 +60,8 @@ public function handle(MonitorAction $action): int ])); }); - return $passable->hasUnhealthyStatuses() ? 1 : 0; + return $passable->hasUnhealthyStatuses() + ? Command::FAILURE + : Command::SUCCESS; } } diff --git a/src/Console/RunBackupCommand.php b/src/Console/RunBackupCommand.php index a19d1d1..fdbc2e9 100644 --- a/src/Console/RunBackupCommand.php +++ b/src/Console/RunBackupCommand.php @@ -12,7 +12,6 @@ /** * Class RunBackupCommand * - * @package Arcanedev\LaravelBackup\Console * @author ARCANEDEV */ class RunBackupCommand extends Command @@ -23,7 +22,7 @@ class RunBackupCommand extends Command */ /** @var string */ - protected $signature = 'backup:run {--filename=} {--only-db} {--db-name=*} {--only-files} {--only-to-disk=} {--disable-notifications}'; + protected $signature = 'backup:run {--filename=} {--only-db} {--db-name=*} {--only-files} {--only-to-disk=} {--disable-notifications} {--timeout=}'; /** @var string */ protected $description = 'Run the backup.'; @@ -44,21 +43,46 @@ public function handle(BackupAction $action): int { $this->comment(__('Starting backup...')); + $this->setTimeout($this->option('timeout')); + try { - $options = Arr::only($this->options(), [ - 'filename', 'only-db', 'db-name', 'only-files', 'only-to-disk', 'disable-notifications', - ]); + $allowedOptions = [ + 'filename', + 'only-db', + 'db-name', + 'only-files', + 'only-to-disk', + 'disable-notifications', + ]; - $action->execute($options); + $action->execute(Arr::only($this->options(), $allowedOptions)); $this->comment(__('Backup completed!')); - return 0; + return Command::SUCCESS; } catch (Exception $e) { $this->error(__('Backup failed because: :message', ['message' => $e->getMessage()])); - return 1; + return Command::FAILURE; + } + } + + /* ----------------------------------------------------------------- + | Other Methods + | ----------------------------------------------------------------- + */ + + + /** + * Set timeout. + * + * @param string|int|null $timeout + */ + private function setTimeout($timeout): void + { + if ($timeout && is_numeric($timeout)) { + set_time_limit((int) $this->option('timeout')); } } } diff --git a/src/Database/Command.php b/src/Database/Command.php index 50d1b64..19f5797 100644 --- a/src/Database/Command.php +++ b/src/Database/Command.php @@ -9,7 +9,6 @@ /** * Class Command * - * @package Arcanedev\LaravelBackup\Database * @author ARCANEDEV */ class Command @@ -151,12 +150,15 @@ public function toString(string $glue = ' '): string */ public function echoToFile(string $dumpFile, Compressor $compressor = null): string { - $command = $this->toString(); $dumpFile = '"'.addcslashes($dumpFile, '\\"').'"'; - return $compressor - ? "(((({$command}; echo \$? >&3) | {$compressor->useCommand()} > {$dumpFile}) 3>&1) | (read x; exit \$x))" - : "{$command} > {$dumpFile}"; + $command = $this->toString(); + + if (is_null($compressor)) { + return "{$command} > {$dumpFile}"; + } + + return "(((({$command}; echo \$? >&3) | {$compressor->useCommand()} > {$dumpFile}) 3>&1) | (read x; exit \$x))"; } /* ----------------------------------------------------------------- diff --git a/src/Database/Compressors/GzipCompressor.php b/src/Database/Compressors/GzipCompressor.php index f21b467..1e4fd64 100644 --- a/src/Database/Compressors/GzipCompressor.php +++ b/src/Database/Compressors/GzipCompressor.php @@ -1,5 +1,7 @@ */ class GzipCompressor implements Compressor diff --git a/src/Database/Contracts/Compressor.php b/src/Database/Contracts/Compressor.php index 4d18a78..9f13afd 100644 --- a/src/Database/Contracts/Compressor.php +++ b/src/Database/Contracts/Compressor.php @@ -1,15 +1,26 @@ + * @author ARCANEDEV */ interface Compressor { + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- + */ + + /** + * Get the compressor command. + * + * @return string + */ public function useCommand(): string; /** diff --git a/src/Database/DbDumperManager.php b/src/Database/DbDumperManager.php index 8e00982..7790dd0 100644 --- a/src/Database/DbDumperManager.php +++ b/src/Database/DbDumperManager.php @@ -5,18 +5,23 @@ namespace Arcanedev\LaravelBackup\Database; use Arcanedev\LaravelBackup\Database\Dumpers\{ - AbstractDumper, MongoDbDumper, MySqlDumper, PostgreSqlDumper, SqliteDumper -}; + AbstractDumper, + MongoDbDumper, + MySqlDumper, + PostgreSqlDumper, + SqliteDumper}; use Arcanedev\LaravelBackup\Exceptions\CannotCreateDbDumper; use Exception; use Illuminate\Contracts\Foundation\Application; use Illuminate\Database\ConfigurationUrlParser; -use Illuminate\Support\{Arr, Collection, Str}; +use Illuminate\Support\{ + Arr, + Collection, + Str}; /** * Class DbDumperManager * - * @package Arcanedev\LaravelBackup\Database * @author ARCANEDEV */ class DbDumperManager @@ -171,7 +176,8 @@ protected function createMongodbDumper(array $config): MongoDbDumper */ protected function createDumperWithConnection(string $class, array $config): AbstractDumper { - return tap($this->createDumper($class, $config), function ($dumper) use ($config) { + return tap($this->createDumper($class, $config), function ($dumper) use ($config): void { + /** @var \Arcanedev\LaravelBackup\Database\Dumpers\Concerns\HasDbConnection $dumper */ $dumper->setHost(Arr::first(Arr::wrap($config['host'] ?? ''))) ->setUserName($config['username'] ?? '') ->setPassword($config['password'] ?? ''); @@ -179,6 +185,10 @@ protected function createDumperWithConnection(string $class, array $config): Abs if (isset($config['port'])) { $dumper->setPort((string) $config['port']); } + + if (isset($config['unix_socket'])) { + $dumper->setSocket($config['unix_socket']); + } }); } @@ -198,6 +208,10 @@ protected function createDumper(string $class, array $config): AbstractDumper if (isset($config['dump'])) { static::processExtraDumpParameters($dumper, $config['dump']); } + + if ($compressor = $this->app['config']['backup.backup.db-dump-compressor']) { + $dumper->setCompressor($this->app->make($compressor)); + } }); } diff --git a/src/Database/DdDumper.php b/src/Database/DdDumper.php index 5e1fece..03c4178 100644 --- a/src/Database/DdDumper.php +++ b/src/Database/DdDumper.php @@ -5,9 +5,8 @@ namespace Arcanedev\LaravelBackup\Database; /** - * Class DatabaseDumper + * Class DdDumper * - * @package Arcanedev\LaravelBackup * @author ARCANEDEV */ class DdDumper @@ -85,9 +84,15 @@ public function setPath(string $path): self public function dump(string $connection, string $filename = null): string { $filename = $filename ?: $connection; - $path = $this->path().DIRECTORY_SEPARATOR."dump-{$filename}.sql"; - $this->manager->dumper($connection)->dump($path); + $path = $this->path().DIRECTORY_SEPARATOR."dump-{$filename}.sql"; + + $dumper = $this->manager->dumper($connection); + + if ($compressor = $dumper->getCompressor()) + $path .= ".{$compressor->usedExtension()}"; + + $dumper->dump($path); return $path; } diff --git a/src/Database/Dumpers/AbstractDumper.php b/src/Database/Dumpers/AbstractDumper.php index d5e858c..a359206 100644 --- a/src/Database/Dumpers/AbstractDumper.php +++ b/src/Database/Dumpers/AbstractDumper.php @@ -11,7 +11,6 @@ /** * Class AbstractDumper * - * @package Arcanedev\LaravelBackup\Database\Dumpers * @author ARCANEDEV */ abstract class AbstractDumper diff --git a/src/Database/Dumpers/Concerns/HasDbConnection.php b/src/Database/Dumpers/Concerns/HasDbConnection.php index b012a15..1ce1c51 100644 --- a/src/Database/Dumpers/Concerns/HasDbConnection.php +++ b/src/Database/Dumpers/Concerns/HasDbConnection.php @@ -9,7 +9,6 @@ /** * Trait HasDbConnection * - * @package Arcanedev\LaravelBackup\Database\Dumpers\Concerns * @author ARCANEDEV */ trait HasDbConnection @@ -141,9 +140,16 @@ public function setPort(string $port): self */ public function getPort(): ?string { - return $this->port; + return $this->port ?: $this->getDefaultPort(); } + /** + * Get the default port. + * + * @return string|null + */ + abstract protected function getDefaultPort(): ?string; + /** * Set the socket. * diff --git a/src/Database/Dumpers/MongoDbDumper.php b/src/Database/Dumpers/MongoDbDumper.php index bfde27e..bb9d606 100644 --- a/src/Database/Dumpers/MongoDbDumper.php +++ b/src/Database/Dumpers/MongoDbDumper.php @@ -11,7 +11,6 @@ /** * Class MongoDbDumper * - * @package Arcanedev\LaravelBackup\Database\Dumpers * @author ARCANEDEV */ class MongoDbDumper extends AbstractDumper @@ -35,23 +34,20 @@ class MongoDbDumper extends AbstractDumper protected $authenticationDatabase = null; /* ----------------------------------------------------------------- - | Constructor + | Getters & Setters | ----------------------------------------------------------------- */ /** - * MongoDbDumper constructor. + * Get the default port. + * + * @return string */ - public function __construct() + protected function getDefaultPort(): string { - $this->setPort('27017'); + return '27017'; } - /* ----------------------------------------------------------------- - | Getters & Setters - | ----------------------------------------------------------------- - */ - /** * @param string $collection * @@ -94,7 +90,7 @@ public function dump(string $dumpFile): void $this->getDumpCommand($dumpFile) ); - $this->checkIfDumpWasSuccessFul($process, $dumpFile); + static::checkIfDumpWasSuccessFul($process, $dumpFile); } /** diff --git a/src/Database/Dumpers/MySqlDumper.php b/src/Database/Dumpers/MySqlDumper.php index f5add80..d1ddec4 100644 --- a/src/Database/Dumpers/MySqlDumper.php +++ b/src/Database/Dumpers/MySqlDumper.php @@ -11,7 +11,6 @@ /** * Class MySqlDumper * - * @package Arcanedev\LaravelBackup\Database\Dumpers * @author ARCANEDEV */ class MySqlDumper extends AbstractDumper @@ -61,23 +60,20 @@ class MySqlDumper extends AbstractDumper protected $createTables = true; /* ----------------------------------------------------------------- - | Constructor + | Setters & Getters | ----------------------------------------------------------------- */ /** - * MySqlDumper constructor. + * Get the default port. + * + * @return string */ - public function __construct() + protected function getDefaultPort(): string { - $this->setPort('3306'); + return '3306'; } - /* ----------------------------------------------------------------- - | Setters & Getters - | ----------------------------------------------------------------- - */ - /** * @return $this */ diff --git a/src/Database/Dumpers/PostgreSqlDumper.php b/src/Database/Dumpers/PostgreSqlDumper.php index e888f0f..e04ec90 100644 --- a/src/Database/Dumpers/PostgreSqlDumper.php +++ b/src/Database/Dumpers/PostgreSqlDumper.php @@ -11,7 +11,6 @@ /** * Class PostgreSqlDumper * - * @package Arcanedev\LaravelBackup\Database\Dumpers * @author ARCANEDEV */ class PostgreSqlDumper extends AbstractDumper @@ -35,23 +34,20 @@ class PostgreSqlDumper extends AbstractDumper protected $createTables = true; /* ----------------------------------------------------------------- - | Constructor + | Getters & Setters | ----------------------------------------------------------------- */ /** - * PostgreSqlDumper constructor. + * Get the default port. + * + * @return string */ - public function __construct() + protected function getDefaultPort(): string { - $this->setPort('5432'); + return '5432'; } - /* ----------------------------------------------------------------- - | Getters & Setters - | ----------------------------------------------------------------- - */ - /** * @return $this */ @@ -112,7 +108,7 @@ public function dump(string $dumpFile): void $this->getEnvironmentVariablesForDumpCommand($temporaryCredentialsFile) ); - $this->checkIfDumpWasSuccessFul($process, $dumpFile); + static::checkIfDumpWasSuccessFul($process, $dumpFile); } /** diff --git a/src/Database/Dumpers/SqliteDumper.php b/src/Database/Dumpers/SqliteDumper.php index a0508c8..be4a811 100644 --- a/src/Database/Dumpers/SqliteDumper.php +++ b/src/Database/Dumpers/SqliteDumper.php @@ -9,7 +9,6 @@ /** * Class SqliteDumper * - * @package Arcanedev\LaravelBackup\Database\Dumpers * @author ARCANEDEV */ class SqliteDumper extends AbstractDumper @@ -44,7 +43,6 @@ public function getDumpCommand(string $dumpFile): string { return Command::make([ "echo 'BEGIN IMMEDIATE;\n.dump' | '{$this->dumpBinaryPath}sqlite3' --bail '{$this->getDbName()}'" - ]) - ->echoToFile($dumpFile, $this->getCompressor()); + ])->echoToFile($dumpFile, $this->getCompressor()); } } diff --git a/src/Entities/Backup.php b/src/Entities/Backup.php index 9c43442..90102b3 100644 --- a/src/Entities/Backup.php +++ b/src/Entities/Backup.php @@ -7,15 +7,22 @@ use Arcanedev\LaravelBackup\Helpers\Format; use Carbon\Carbon; use Illuminate\Contracts\Filesystem\Filesystem; +use InvalidArgumentException; /** * Class Backup * - * @package Arcanedev\LaravelBackup\Entities * @author ARCANEDEV */ class Backup { + /* ----------------------------------------------------------------- + | Constants + | ----------------------------------------------------------------- + */ + + public const FILENAME_FORMAT = 'Ymd-His.\z\i\p'; + /* ----------------------------------------------------------------- | Traits | ----------------------------------------------------------------- @@ -55,6 +62,8 @@ public function __construct(Filesystem $disk, string $path) { $this->setDisk($disk); $this->setPath($path); + + $this->exists = true; } /* ----------------------------------------------------------------- @@ -108,7 +117,14 @@ public function exists(): bool public function date(): Carbon { if ($this->date === null) { - $this->date = Carbon::createFromTimestamp($this->disk()->lastModified($this->path())); + try { + // try to parse the date from the filename + $this->date = Carbon::createFromFormat(static::FILENAME_FORMAT, basename($this->path)); + } + catch (InvalidArgumentException $e) { + // if that fails, ask the (remote) filesystem + $this->date = Carbon::createFromTimestamp($this->disk->lastModified($this->path)); + } } return $this->date; @@ -159,8 +175,8 @@ public function stream() */ public function delete(): bool { - $this->exists = null; - - return $this->disk()->delete($this->path()); + return tap($this->disk()->delete($this->path()), function () { + $this->exists = false; + }); } } diff --git a/src/Entities/BackupCollection.php b/src/Entities/BackupCollection.php index 54b07a7..b045c5a 100644 --- a/src/Entities/BackupCollection.php +++ b/src/Entities/BackupCollection.php @@ -4,8 +4,7 @@ namespace Arcanedev\LaravelBackup\Entities; -use Arcanedev\LaravelBackup\Helpers\FileChecker; -use Arcanedev\LaravelBackup\Helpers\Format; +use Arcanedev\LaravelBackup\Helpers\{FileChecker, Format}; use Carbon\Carbon; use Illuminate\Contracts\Filesystem\Filesystem; use Illuminate\Support\Collection; @@ -13,7 +12,6 @@ /** * Class BackupCollection * - * @package Arcanedev\LaravelBackup\Entities * @author ARCANEDEV */ class BackupCollection extends Collection diff --git a/src/Entities/BackupDestination.php b/src/Entities/BackupDestination.php index abe665d..7edc05f 100644 --- a/src/Entities/BackupDestination.php +++ b/src/Entities/BackupDestination.php @@ -14,7 +14,6 @@ /** * Class BackupDestination * - * @package Arcanedev\LaravelBackup\Entities * @author ARCANEDEV */ class BackupDestination diff --git a/src/Entities/BackupDestinationCollection.php b/src/Entities/BackupDestinationCollection.php index 1f08976..6b0f92e 100644 --- a/src/Entities/BackupDestinationCollection.php +++ b/src/Entities/BackupDestinationCollection.php @@ -10,7 +10,6 @@ /** * Class BackupDestinationCollection * - * @package Arcanedev\LaravelBackup\Entities * @author ARCANEDEV */ class BackupDestinationCollection extends Collection diff --git a/src/Entities/BackupDestinationStatus.php b/src/Entities/BackupDestinationStatus.php index 4d6890a..4b5b101 100644 --- a/src/Entities/BackupDestinationStatus.php +++ b/src/Entities/BackupDestinationStatus.php @@ -12,7 +12,6 @@ /** * Class BackupDestinationStatus * - * @package Arcanedev\LaravelBackup\Entities * @author ARCANEDEV */ class BackupDestinationStatus diff --git a/src/Entities/BackupDestinationStatusCollection.php b/src/Entities/BackupDestinationStatusCollection.php index 5e8bb59..e6a4b94 100644 --- a/src/Entities/BackupDestinationStatusCollection.php +++ b/src/Entities/BackupDestinationStatusCollection.php @@ -9,7 +9,6 @@ /** * Class BackupDestinationStatusCollection * - * @package Arcanedev\LaravelBackup\Entities * @author ARCANEDEV */ class BackupDestinationStatusCollection extends Collection diff --git a/src/Entities/Concerns/HasDisk.php b/src/Entities/Concerns/HasDisk.php index 2f008dd..6a357b3 100644 --- a/src/Entities/Concerns/HasDisk.php +++ b/src/Entities/Concerns/HasDisk.php @@ -10,7 +10,6 @@ /** * Trait HasDisk * - * @package Arcanedev\LaravelBackup\Entities\Concerns * @author ARCANEDEV */ trait HasDisk diff --git a/src/Entities/Manifest.php b/src/Entities/Manifest.php index caf113e..1375b68 100644 --- a/src/Entities/Manifest.php +++ b/src/Entities/Manifest.php @@ -11,7 +11,6 @@ /** * Class Manifest * - * @package Arcanedev\LaravelBackup\Entities * @author ARCANEDEV */ class Manifest implements Arrayable, JsonSerializable diff --git a/src/Entities/Notifiable.php b/src/Entities/Notifiable.php index a605d70..9cfda66 100644 --- a/src/Entities/Notifiable.php +++ b/src/Entities/Notifiable.php @@ -9,7 +9,6 @@ /** * Class Notifiable * - * @package Arcanedev\LaravelBackup\Entities * @author ARCANEDEV */ class Notifiable diff --git a/src/Entities/Period.php b/src/Entities/Period.php index 387e2c0..b4d0376 100644 --- a/src/Entities/Period.php +++ b/src/Entities/Period.php @@ -10,7 +10,6 @@ /** * Class Period * - * @package Arcanedev\LaravelBackup\Entities * @author ARCANEDEV */ class Period diff --git a/src/Events/BackupActionHasFailed.php b/src/Events/BackupActionHasFailed.php index 634f4f7..152dd05 100644 --- a/src/Events/BackupActionHasFailed.php +++ b/src/Events/BackupActionHasFailed.php @@ -8,9 +8,8 @@ use Exception; /** - * Class BackupHasFailed + * Class BackupActionHasFailed * - * @package Arcanedev\LaravelBackup\Events * @author ARCANEDEV */ class BackupActionHasFailed diff --git a/src/Events/BackupActionWasSuccessful.php b/src/Events/BackupActionWasSuccessful.php index c2fb477..ccc7f80 100644 --- a/src/Events/BackupActionWasSuccessful.php +++ b/src/Events/BackupActionWasSuccessful.php @@ -7,9 +7,8 @@ use Arcanedev\LaravelBackup\Actions\Backup\BackupPassable; /** - * Class BackupWasSuccessful + * Class BackupActionWasSuccessful * - * @package Arcanedev\LaravelBackup\Events * @author ARCANEDEV */ class BackupActionWasSuccessful diff --git a/src/Events/BackupManifestWasCreated.php b/src/Events/BackupManifestWasCreated.php index d9d5eed..60856ed 100644 --- a/src/Events/BackupManifestWasCreated.php +++ b/src/Events/BackupManifestWasCreated.php @@ -9,7 +9,6 @@ /** * Class BackupManifestWasCreated * - * @package Arcanedev\LaravelBackup\Events * @author ARCANEDEV */ class BackupManifestWasCreated diff --git a/src/Events/BackupZipWasCreated.php b/src/Events/BackupZipWasCreated.php index a0b570c..7353a20 100644 --- a/src/Events/BackupZipWasCreated.php +++ b/src/Events/BackupZipWasCreated.php @@ -9,7 +9,6 @@ /** * Class BackupZipWasCreated * - * @package Arcanedev\LaravelBackup\Events * @author ARCANEDEV */ class BackupZipWasCreated diff --git a/src/Events/CleanupActionHasFailed.php b/src/Events/CleanupActionHasFailed.php index d8b9db4..8c9edc3 100644 --- a/src/Events/CleanupActionHasFailed.php +++ b/src/Events/CleanupActionHasFailed.php @@ -10,7 +10,6 @@ /** * Class CleanupActionHasFailed * - * @package Arcanedev\LaravelBackup\Events * @author ARCANEDEV */ class CleanupActionHasFailed diff --git a/src/Events/CleanupActionWasSuccessful.php b/src/Events/CleanupActionWasSuccessful.php index 0bf317e..2d9eaec 100644 --- a/src/Events/CleanupActionWasSuccessful.php +++ b/src/Events/CleanupActionWasSuccessful.php @@ -7,9 +7,8 @@ use Arcanedev\LaravelBackup\Actions\Cleanup\CleanupPassable; /** - * Class CleanupWasSuccessful + * Class CleanupActionWasSuccessful * - * @package Arcanedev\LaravelBackup\Events * @author ARCANEDEV */ class CleanupActionWasSuccessful diff --git a/src/Events/HealthyBackupsWasFound.php b/src/Events/HealthyBackupsWasFound.php index fac1fe1..aa05dfd 100644 --- a/src/Events/HealthyBackupsWasFound.php +++ b/src/Events/HealthyBackupsWasFound.php @@ -10,7 +10,6 @@ /** * Class HealthyBackupsWasFound * - * @package Arcanedev\LaravelBackup\Events * @author ARCANEDEV */ class HealthyBackupsWasFound diff --git a/src/Events/MonitorActionHasFailed.php b/src/Events/MonitorActionHasFailed.php index 63d751d..bd1ef14 100644 --- a/src/Events/MonitorActionHasFailed.php +++ b/src/Events/MonitorActionHasFailed.php @@ -10,7 +10,6 @@ /** * Class MonitorActionHasFailed * - * @package Arcanedev\LaravelBackup\Events * @author ARCANEDEV */ class MonitorActionHasFailed diff --git a/src/Events/MonitorActionWasSuccessful.php b/src/Events/MonitorActionWasSuccessful.php index 084162f..e3705b2 100644 --- a/src/Events/MonitorActionWasSuccessful.php +++ b/src/Events/MonitorActionWasSuccessful.php @@ -9,7 +9,6 @@ /** * Class MonitorActionWasSuccessful * - * @package Arcanedev\LaravelBackup\Events * @author ARCANEDEV */ class MonitorActionWasSuccessful diff --git a/src/Events/UnhealthyBackupsWasFound.php b/src/Events/UnhealthyBackupsWasFound.php index a39395e..14bd2ca 100644 --- a/src/Events/UnhealthyBackupsWasFound.php +++ b/src/Events/UnhealthyBackupsWasFound.php @@ -10,7 +10,6 @@ /** * Class UnhealthyBackupsWasFound * - * @package Arcanedev\LaravelBackup\Events * @author ARCANEDEV */ class UnhealthyBackupsWasFound diff --git a/src/Exceptions/CannotCreateDbDumper.php b/src/Exceptions/CannotCreateDbDumper.php index 7bb1a7e..7cc4ba0 100644 --- a/src/Exceptions/CannotCreateDbDumper.php +++ b/src/Exceptions/CannotCreateDbDumper.php @@ -9,7 +9,6 @@ /** * Class CannotCreateDbDumper * - * @package Arcanedev\LaravelBackup\Exceptions * @author ARCANEDEV */ class CannotCreateDbDumper extends Exception diff --git a/src/Exceptions/CannotSetDatabaseParameter.php b/src/Exceptions/CannotSetDatabaseParameter.php index a9a813d..c619842 100644 --- a/src/Exceptions/CannotSetDatabaseParameter.php +++ b/src/Exceptions/CannotSetDatabaseParameter.php @@ -9,7 +9,6 @@ /** * Class CannotSetDatabaseParameter * - * @package Arcanedev\LaravelBackup\Exceptions * @author ARCANEDEV */ class CannotSetDatabaseParameter extends Exception diff --git a/src/Exceptions/CannotStartDatabaseDump.php b/src/Exceptions/CannotStartDatabaseDump.php index 01fb84d..7d99c5d 100644 --- a/src/Exceptions/CannotStartDatabaseDump.php +++ b/src/Exceptions/CannotStartDatabaseDump.php @@ -9,7 +9,6 @@ /** * Class CannotStartDatabaseDump * - * @package Arcanedev\LaravelBackup\Exceptions * @author ARCANEDEV */ class CannotStartDatabaseDump extends Exception diff --git a/src/Exceptions/DatabaseDumpFailed.php b/src/Exceptions/DatabaseDumpFailed.php index 0d177e5..f9f3dc0 100644 --- a/src/Exceptions/DatabaseDumpFailed.php +++ b/src/Exceptions/DatabaseDumpFailed.php @@ -10,7 +10,6 @@ /** * Class DatabaseDumpFailed * - * @package Arcanedev\LaravelBackup\Exceptions * @author ARCANEDEV */ class DatabaseDumpFailed extends Exception diff --git a/src/Exceptions/InvalidBackupDestination.php b/src/Exceptions/InvalidBackupDestination.php index a23c99d..a4f747d 100644 --- a/src/Exceptions/InvalidBackupDestination.php +++ b/src/Exceptions/InvalidBackupDestination.php @@ -9,7 +9,6 @@ /** * Class InvalidBackupDestination * - * @package Arcanedev\LaravelBackup\Exceptions * @author ARCANEDEV */ class InvalidBackupDestination extends Exception diff --git a/src/Exceptions/InvalidDbDriverException.php b/src/Exceptions/InvalidDbDriverException.php index 84a3395..dc9c30b 100644 --- a/src/Exceptions/InvalidDbDriverException.php +++ b/src/Exceptions/InvalidDbDriverException.php @@ -9,7 +9,6 @@ /** * Class InvalidDbDriverException * - * @package Arcanedev\LaravelBackup\Exceptions * @author ARCANEDEV */ class InvalidDbDriverException extends InvalidArgumentException diff --git a/src/Exceptions/InvalidHealthCheck.php b/src/Exceptions/InvalidHealthCheck.php index 9c1b9a3..b971d28 100644 --- a/src/Exceptions/InvalidHealthCheck.php +++ b/src/Exceptions/InvalidHealthCheck.php @@ -7,7 +7,6 @@ /** * Class InvalidHealthCheck * - * @package Arcanedev\LaravelBackup\Exceptions * @author ARCANEDEV */ class InvalidHealthCheck extends \Exception diff --git a/src/Exceptions/InvalidTaskOptions.php b/src/Exceptions/InvalidTaskOptions.php index bee6cda..5307d67 100644 --- a/src/Exceptions/InvalidTaskOptions.php +++ b/src/Exceptions/InvalidTaskOptions.php @@ -9,7 +9,6 @@ /** * Class InvalidTaskOptions * - * @package Arcanedev\LaravelBackup\Exceptions * @author ARCANEDEV */ class InvalidTaskOptions extends Exception diff --git a/src/Exceptions/ZipException.php b/src/Exceptions/ZipException.php index 385bce4..470456e 100644 --- a/src/Exceptions/ZipException.php +++ b/src/Exceptions/ZipException.php @@ -4,15 +4,15 @@ namespace Arcanedev\LaravelBackup\Exceptions; +use Exception; use ZipArchive; /** * Class ZipException * - * @package Arcanedev\LaravelBackup\Exceptions * @author ARCANEDEV */ -class ZipException extends \Exception +class ZipException extends Exception { /* ----------------------------------------------------------------- | Constants diff --git a/src/Helpers/FileChecker.php b/src/Helpers/FileChecker.php index e0989dc..d378e95 100644 --- a/src/Helpers/FileChecker.php +++ b/src/Helpers/FileChecker.php @@ -10,7 +10,6 @@ /** * Class FileChecker * - * @package Arcanedev\LaravelBackup\Helpers * @author ARCANEDEV */ class FileChecker diff --git a/src/Helpers/FilesSelector.php b/src/Helpers/FilesSelector.php index 5485bcb..c386e34 100644 --- a/src/Helpers/FilesSelector.php +++ b/src/Helpers/FilesSelector.php @@ -12,7 +12,6 @@ /** * Class FilesSelector * - * @package Arcanedev\LaravelBackup\Helpers * @author ARCANEDEV */ class FilesSelector @@ -34,6 +33,9 @@ class FilesSelector /** @var bool */ protected $shouldFollowLinks = false; + /** @var bool */ + protected $shouldIgnoreUnreadableDirectories = false; + /* ----------------------------------------------------------------- | Constructor | ----------------------------------------------------------------- @@ -133,6 +135,20 @@ public function shouldFollowLinks(bool $shouldFollowLinks): self return $this; } + /** + * Set if it should ignore the unreadable directories. + * + * @param bool $ignoreUnreadableDirectories + * + * @return $this + */ + public function shouldIgnoreUnreadableDirs(bool $ignoreUnreadableDirectories): self + { + $this->shouldIgnoreUnreadableDirectories = $ignoreUnreadableDirectories; + + return $this; + } + /* ----------------------------------------------------------------- | Main Methods | ----------------------------------------------------------------- @@ -166,6 +182,10 @@ public function selected(): Generator $this->finder->followLinks(); } + if ($this->shouldIgnoreUnreadableDirectories) { + $this->finder->ignoreUnreadableDirs(); + } + /** * @var \Illuminate\Support\Collection $includedFiles * @var \Illuminate\Support\Collection $includedDirectories diff --git a/src/Helpers/Format.php b/src/Helpers/Format.php index 54d9775..209b09a 100644 --- a/src/Helpers/Format.php +++ b/src/Helpers/Format.php @@ -9,7 +9,6 @@ /** * Class Format * - * @package Arcanedev\LaravelBackup\Helpers * @author ARCANEDEV */ class Format diff --git a/src/Helpers/Zip.php b/src/Helpers/Zip.php index 78d31ea..4473b07 100644 --- a/src/Helpers/Zip.php +++ b/src/Helpers/Zip.php @@ -13,7 +13,6 @@ /** * Class Zip * - * @package Arcanedev\LaravelBackup\Helpers * @author ARCANEDEV * * @mixin \ZipArchive diff --git a/src/Listeners/Concerns/HandleNotifications.php b/src/Listeners/Concerns/HandleNotifications.php index c5ffaa3..b49c8ab 100644 --- a/src/Listeners/Concerns/HandleNotifications.php +++ b/src/Listeners/Concerns/HandleNotifications.php @@ -7,7 +7,6 @@ /** * Trait HandleNotifications * - * @package Arcanedev\LaravelBackup\Listeners\Concerns * @author ARCANEDEV */ trait HandleNotifications diff --git a/src/Listeners/SendBackupHasFailedNotification.php b/src/Listeners/SendBackupHasFailedNotification.php index 78a4748..5ed2e97 100644 --- a/src/Listeners/SendBackupHasFailedNotification.php +++ b/src/Listeners/SendBackupHasFailedNotification.php @@ -11,7 +11,6 @@ /** * Class SendBackupHasFailedNotification * - * @package Arcanedev\LaravelBackup\Listeners * @author ARCANEDEV */ class SendBackupHasFailedNotification diff --git a/src/Listeners/SendBackupWasSuccessfulNotification.php b/src/Listeners/SendBackupWasSuccessfulNotification.php index 04f76cb..3db8929 100644 --- a/src/Listeners/SendBackupWasSuccessfulNotification.php +++ b/src/Listeners/SendBackupWasSuccessfulNotification.php @@ -11,7 +11,6 @@ /** * Class SendBackupWasSuccessfulNotification * - * @package Arcanedev\LaravelBackup\Listeners * @author ARCANEDEV */ class SendBackupWasSuccessfulNotification diff --git a/src/Listeners/SendCleanupHasFailedNotification.php b/src/Listeners/SendCleanupHasFailedNotification.php index 63c1bf7..06ab8c3 100644 --- a/src/Listeners/SendCleanupHasFailedNotification.php +++ b/src/Listeners/SendCleanupHasFailedNotification.php @@ -11,7 +11,6 @@ /** * Class SendCleanupHasFailedNotification * - * @package Arcanedev\LaravelBackup\Listeners * @author ARCANEDEV */ class SendCleanupHasFailedNotification diff --git a/src/Listeners/SendCleanupWasSuccessfulNotification.php b/src/Listeners/SendCleanupWasSuccessfulNotification.php index 63cb907..de1ae4b 100644 --- a/src/Listeners/SendCleanupWasSuccessfulNotification.php +++ b/src/Listeners/SendCleanupWasSuccessfulNotification.php @@ -11,7 +11,6 @@ /** * Class SendCleanupWasSuccessfulNotification * - * @package Arcanedev\LaravelBackup\Listeners * @author ARCANEDEV */ class SendCleanupWasSuccessfulNotification diff --git a/src/Listeners/SendHealthyBackupWasFoundNotification.php b/src/Listeners/SendHealthyBackupWasFoundNotification.php index 5f319b8..6466d32 100644 --- a/src/Listeners/SendHealthyBackupWasFoundNotification.php +++ b/src/Listeners/SendHealthyBackupWasFoundNotification.php @@ -11,7 +11,6 @@ /** * Class SendHealthyBackupWasFoundNotification * - * @package Arcanedev\LaravelBackup\Listeners * @author ARCANEDEV */ class SendHealthyBackupWasFoundNotification diff --git a/src/Listeners/SendUnhealthyBackupWasFoundNotification.php b/src/Listeners/SendUnhealthyBackupWasFoundNotification.php index d7bf627..c9b510c 100644 --- a/src/Listeners/SendUnhealthyBackupWasFoundNotification.php +++ b/src/Listeners/SendUnhealthyBackupWasFoundNotification.php @@ -11,7 +11,6 @@ /** * Class SendUnhealthyBackupWasFoundNotification * - * @package Arcanedev\LaravelBackup\Listeners * @author ARCANEDEV */ class SendUnhealthyBackupWasFoundNotification diff --git a/src/Notifications/AbstractNotification.php b/src/Notifications/AbstractNotification.php index 0b4233a..8a52ad1 100644 --- a/src/Notifications/AbstractNotification.php +++ b/src/Notifications/AbstractNotification.php @@ -13,7 +13,6 @@ /** * Class AbstractNotification * - * @package Arcanedev\LaravelBackup\Notifications * @author ARCANEDEV */ abstract class AbstractNotification extends Notification @@ -64,9 +63,9 @@ public function setEvent($event): self */ public function via($notifiable): array { - $notificationChannels = config('backup.notifications.supported.'.static::class, []); + $channels = static::config('supported.'.static::class, []); - return array_filter($notificationChannels); + return array_filter($channels); } /** @@ -161,8 +160,8 @@ protected function backupDestinationProperties(BackupDestination $backupDestinat */ protected static function makeMailMessage(): MailMessage { - $address = config('backup.notifications.mail.from.address', config('mail.from.address')); - $name = config('backup.notifications.mail.from.name', config('mail.from.name')); + $address = static::config('mail.from.address', config('mail.from.address')); + $name = static::config('mail.from.name', config('mail.from.name')); return (new MailMessage)->from($address, $name); } @@ -174,10 +173,23 @@ protected static function makeMailMessage(): MailMessage */ protected static function makeSlackMessage(): SlackMessage { - $username = config('backup.notifications.slack.username'); - $icon = config('backup.notifications.slack.icon'); - $channel = config('backup.notifications.slack.channel'); + $username = static::config('slack.username'); + $icon = static::config('slack.icon'); + $channel = static::config('slack.channel'); return (new SlackMessage)->from($username, $icon)->to($channel); } + + /** + * Get the notification's config. + * + * @param string $key + * @param mixed|null $default + * + * @return mixed + */ + private static function config(string $key, $default = null) + { + return config("backup.notifications.{$key}", $default); + } } diff --git a/src/Notifications/BackupHasFailedNotification.php b/src/Notifications/BackupHasFailedNotification.php index 0f077fa..f40a9f2 100644 --- a/src/Notifications/BackupHasFailedNotification.php +++ b/src/Notifications/BackupHasFailedNotification.php @@ -8,9 +8,8 @@ use Illuminate\Notifications\Messages\{MailMessage, SlackAttachment, SlackMessage}; /** - * Class BackupActionHasFailedNotification + * Class BackupHasFailedNotification * - * @package Arcanedev\LaravelBackup\Notifications * @author ARCANEDEV */ class BackupHasFailedNotification extends AbstractNotification diff --git a/src/Notifications/BackupWasSuccessfulNotification.php b/src/Notifications/BackupWasSuccessfulNotification.php index bf58259..0a41922 100644 --- a/src/Notifications/BackupWasSuccessfulNotification.php +++ b/src/Notifications/BackupWasSuccessfulNotification.php @@ -10,7 +10,6 @@ /** * Class BackupWasSuccessfulNotification * - * @package Arcanedev\LaravelBackup\Notifications * @author ARCANEDEV */ class BackupWasSuccessfulNotification extends AbstractNotification diff --git a/src/Notifications/CleanupHasFailedNotification.php b/src/Notifications/CleanupHasFailedNotification.php index 094b4bf..f58ff52 100644 --- a/src/Notifications/CleanupHasFailedNotification.php +++ b/src/Notifications/CleanupHasFailedNotification.php @@ -10,7 +10,6 @@ /** * Class CleanupHasFailedNotification * - * @package Arcanedev\LaravelBackup\Notifications * @author ARCANEDEV */ class CleanupHasFailedNotification extends AbstractNotification diff --git a/src/Notifications/CleanupWasSuccessfulNotification.php b/src/Notifications/CleanupWasSuccessfulNotification.php index 81a24f9..7d37c50 100644 --- a/src/Notifications/CleanupWasSuccessfulNotification.php +++ b/src/Notifications/CleanupWasSuccessfulNotification.php @@ -10,7 +10,6 @@ /** * Class CleanupWasSuccessfulNotification * - * @package Arcanedev\LaravelBackup\Notifications * @author ARCANEDEV */ class CleanupWasSuccessfulNotification extends AbstractNotification diff --git a/src/Notifications/HealthyBackupsWasFoundNotification.php b/src/Notifications/HealthyBackupsWasFoundNotification.php index e74b518..02da371 100644 --- a/src/Notifications/HealthyBackupsWasFoundNotification.php +++ b/src/Notifications/HealthyBackupsWasFoundNotification.php @@ -8,9 +8,8 @@ use Illuminate\Notifications\Messages\{MailMessage, SlackAttachment, SlackMessage}; /** - * Class HealthyBackupWasFoundNotification + * Class HealthyBackupsWasFoundNotification * - * @package Arcanedev\LaravelBackup\Notifications * @author ARCANEDEV */ class HealthyBackupsWasFoundNotification extends AbstractNotification diff --git a/src/Notifications/UnhealthyBackupsWasFoundNotification.php b/src/Notifications/UnhealthyBackupsWasFoundNotification.php index f1faf50..4205659 100644 --- a/src/Notifications/UnhealthyBackupsWasFoundNotification.php +++ b/src/Notifications/UnhealthyBackupsWasFoundNotification.php @@ -8,9 +8,8 @@ use Illuminate\Notifications\Messages\{MailMessage, SlackAttachment, SlackMessage}; /** - * Class UnhealthyBackupWasFoundNotification + * Class UnhealthyBackupsWasFoundNotification * - * @package Arcanedev\LaravelBackup\Notifications * @author ARCANEDEV */ class UnhealthyBackupsWasFoundNotification extends AbstractNotification diff --git a/src/Providers/DeferredServiceProvider.php b/src/Providers/DeferredServiceProvider.php index 373801f..31b37e0 100644 --- a/src/Providers/DeferredServiceProvider.php +++ b/src/Providers/DeferredServiceProvider.php @@ -12,11 +12,15 @@ /** * Class DeferredServiceProvider * - * @package Arcanedev\LaravelBackup\Providers * @author ARCANEDEV */ class DeferredServiceProvider extends ServiceProvider implements DeferrableProvider { + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- + */ + /** * Register the service provider. */ diff --git a/src/Providers/EventServiceProvider.php b/src/Providers/EventServiceProvider.php index 9a1137b..d4517a1 100644 --- a/src/Providers/EventServiceProvider.php +++ b/src/Providers/EventServiceProvider.php @@ -9,7 +9,6 @@ /** * Class EventServiceProvider * - * @package Arcanedev\LaravelBackup\Providers * @author ARCANEDEV */ class EventServiceProvider extends ServiceProvider diff --git a/tests/Asserts/AssertZipFile.php b/tests/Asserts/AssertZipFile.php index 7f54797..be884cc 100644 --- a/tests/Asserts/AssertZipFile.php +++ b/tests/Asserts/AssertZipFile.php @@ -7,7 +7,6 @@ /** * Trait AssertZipFile * - * @package Arcanedev\LaravelBackup\Tests\Asserts * @author ARCANEDEV */ trait AssertZipFile @@ -16,7 +15,7 @@ trait AssertZipFile * @param string $zipPath * @param array $files */ - protected function assertFilesExistsInZipArchive(string $zipPath, array $files): void + protected static function assertFilesExistsInZipArchive(string $zipPath, array $files): void { foreach ($files as $file) { static::assertFileExistsInZip($zipPath, $file); @@ -27,7 +26,7 @@ protected function assertFilesExistsInZipArchive(string $zipPath, array $files): * @param string $zipPath * @param string $fileName */ - protected function assertFileExistsInZip(string $zipPath, string $fileName): void + protected static function assertFileExistsInZip(string $zipPath, string $fileName): void { static::assertTrue( static::fileExistsInZip($zipPath, $fileName), diff --git a/tests/BackupServiceProviderTest.php b/tests/BackupServiceProviderTest.php index 98122bc..1be89bb 100644 --- a/tests/BackupServiceProviderTest.php +++ b/tests/BackupServiceProviderTest.php @@ -1,53 +1,54 @@ - - */ -class BackupServiceProviderTest extends TestCase -{ - /* ----------------------------------------------------------------- - | Properties - | ----------------------------------------------------------------- - */ - - private $provider; - - /* ----------------------------------------------------------------- - | Main Methods - | ----------------------------------------------------------------- - */ - - protected function setUp(): void - { - parent::setUp(); - - $this->provider = $this->app->make(BackupServiceProvider::class); - } - - /* ----------------------------------------------------------------- - | Tests - | ----------------------------------------------------------------- - */ - - /** @test */ - public function it_can_be_instantiated() - { - $expectations = [ - \Illuminate\Support\ServiceProvider::class, - \Arcanedev\Support\Providers\ServiceProvider::class, - \Arcanedev\Support\Providers\PackageServiceProvider::class, - BackupServiceProvider::class, - ]; - - foreach ($expectations as $expected) { - static::assertInstanceOf($expected, $this->provider); - } - } -} + + */ +class BackupServiceProviderTest extends TestCase +{ + /* ----------------------------------------------------------------- + | Properties + | ----------------------------------------------------------------- + */ + + private $provider; + + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- + */ + + protected function setUp(): void + { + parent::setUp(); + + $this->provider = $this->app->make(BackupServiceProvider::class); + } + + /* ----------------------------------------------------------------- + | Tests + | ----------------------------------------------------------------- + */ + + /** @test */ + public function it_can_be_instantiated() + { + $expectations = [ + \Illuminate\Support\ServiceProvider::class, + \Arcanedev\Support\Providers\ServiceProvider::class, + \Arcanedev\Support\Providers\PackageServiceProvider::class, + BackupServiceProvider::class, + ]; + + foreach ($expectations as $expected) { + static::assertInstanceOf($expected, $this->provider); + } + } +} diff --git a/tests/Concerns/HasDisksManipulation.php b/tests/Concerns/HasDisksManipulation.php index 189bf9d..c57e009 100644 --- a/tests/Concerns/HasDisksManipulation.php +++ b/tests/Concerns/HasDisksManipulation.php @@ -1,5 +1,7 @@ */ trait HasDisksManipulation diff --git a/tests/Concerns/HasFilesManipulation.php b/tests/Concerns/HasFilesManipulation.php index 025cfc5..9a1e26e 100644 --- a/tests/Concerns/HasFilesManipulation.php +++ b/tests/Concerns/HasFilesManipulation.php @@ -10,7 +10,6 @@ /** * Trait HasFilesManipulation * - * @package Arcanedev\LaravelBackup\Tests\Concerns * @author ARCANEDEV */ trait HasFilesManipulation @@ -147,7 +146,7 @@ protected static function deleteTempDirectory(): void * * @throws \Exception */ - protected function fileExistsInZip(string $zipPath, string $fileName): bool + protected static function fileExistsInZip(string $zipPath, string $fileName): bool { foreach (Zip::getFiles($zipPath) as $file) { if ($fileName === $file) diff --git a/tests/Console/CleanupBackupCommandTest.php b/tests/Console/CleanupBackupCommandTest.php index 52f769b..72bbdde 100644 --- a/tests/Console/CleanupBackupCommandTest.php +++ b/tests/Console/CleanupBackupCommandTest.php @@ -15,7 +15,6 @@ /** * Class CleanupBackupCommandTest * - * @package Arcanedev\LaravelBackup\Tests\Console * @author ARCANEDEV */ class CleanupBackupCommandTest extends TestCase diff --git a/tests/Console/MonitorBackupCommandTest.php b/tests/Console/MonitorBackupCommandTest.php index 66cca5f..ea179f9 100644 --- a/tests/Console/MonitorBackupCommandTest.php +++ b/tests/Console/MonitorBackupCommandTest.php @@ -13,7 +13,6 @@ /** * Class MonitorBackupCommandTest * - * @package Arcanedev\LaravelBackup\Tests\Console * @author ARCANEDEV */ class MonitorBackupCommandTest extends TestCase diff --git a/tests/Console/RunBackupCommandTest.php b/tests/Console/RunBackupCommandTest.php index bedac5d..acf85e3 100644 --- a/tests/Console/RunBackupCommandTest.php +++ b/tests/Console/RunBackupCommandTest.php @@ -4,6 +4,7 @@ namespace Arcanedev\LaravelBackup\Tests\Console; +use Arcanedev\LaravelBackup\Database\Compressors\GzipCompressor; use Arcanedev\LaravelBackup\Entities\Notifiable; use Arcanedev\LaravelBackup\Events\{ BackupActionHasFailed, BackupActionWasSuccessful, BackupManifestWasCreated, BackupZipWasCreated, @@ -11,11 +12,11 @@ use Arcanedev\LaravelBackup\Notifications\BackupWasSuccessfulNotification; use Arcanedev\LaravelBackup\Tests\TestCase; use Illuminate\Support\Facades\{Event, Notification, Storage}; +use Illuminate\Console\Command; /** * Class RunBackupCommandTest * - * @package Arcanedev\LaravelBackup\Tests\Console * @author ARCANEDEV */ class RunBackupCommandTest extends TestCase @@ -47,7 +48,7 @@ public function it_can_run_with_default_options(): void $this->artisan('backup:run') ->expectsOutput('Starting backup...') ->expectsOutput('Backup completed!') - ->assertExitCode(0); + ->assertExitCode(Command::SUCCESS); static::assertBackupsExistsInStorages(); @@ -66,7 +67,7 @@ public function it_can_run_with_disabled_notification(): void $this->artisan('backup:run --disable-notifications') ->expectsOutput('Starting backup...') ->expectsOutput('Backup completed!') - ->assertExitCode(0); + ->assertExitCode(Command::SUCCESS); static::assertBackupsExistsInStorages(); @@ -83,7 +84,7 @@ public function it_cannot_run_with_both_only_db_and_only_files_options(): void $this->artisan('backup:run --only-files --only-db') ->expectsOutput('Starting backup...') ->expectsOutput('Backup failed because: Cannot use `only-db` and `only-files` together') - ->assertExitCode(1); + ->assertExitCode(Command::FAILURE); static::assertBackupsMissingInStorages(); @@ -94,6 +95,29 @@ public function it_cannot_run_with_both_only_db_and_only_files_options(): void Event::assertNotDispatched(BackupZipWasCreated::class); } + /** @test */ + public function it_can_run_backup_with_compressor(): void + { + $this->app['config']->set('backup.backup.db-dump-compressor', GzipCompressor::class); + + $this->artisan('backup:run --only-db') + ->expectsOutput('Starting backup...') + ->assertExitCode(Command::SUCCESS); + + static::assertBackupsExistsInStorages(); + + static::assertBackupFilesExistsInZipFile([ + 'databases/dump-sqlite-db-1.sql.gz', + 'databases/dump-sqlite-db-2.sql.gz', + ]); + + Event::assertDispatched(BackupManifestWasCreated::class); + Event::assertDispatched(BackupZipWasCreated::class); + Event::assertDispatched(BackupActionWasSuccessful::class); + + Event::assertNotDispatched(BackupActionHasFailed::class); + } + /* ----------------------------------------------------------------- | Asserts | ----------------------------------------------------------------- @@ -114,6 +138,15 @@ protected static function assertBackupsExistsInStorages(array $disks = ['primary } } + protected static function assertBackupFilesExistsInZipFile(array $files, array $disks = ['primary-storage', 'secondary-storage']) + { + foreach ($disks as $disk) { + $path = Storage::disk($disk)->path('ARCANEDEV/20190101-123030.zip'); + + static::assertFilesExistsInZipArchive($path, $files); + } + } + protected static function assertBackupsMissingInStorages(array $disks = ['primary-storage', 'secondary-storage']) { foreach ($disks as $disk) { diff --git a/tests/Database/DbDumperManagerTest.php b/tests/Database/DbDumperManagerTest.php index e792e52..fee79fe 100644 --- a/tests/Database/DbDumperManagerTest.php +++ b/tests/Database/DbDumperManagerTest.php @@ -10,7 +10,6 @@ /** * Class DbDumperManagerTest * - * @package Arcanedev\LaravelBackup\Tests\Database * @author ARCANEDEV */ class DbDumperManagerTest extends TestCase diff --git a/tests/Database/Dumpers/DumpTestCase.php b/tests/Database/Dumpers/DumpTestCase.php index 7a8aa68..ff9a585 100644 --- a/tests/Database/Dumpers/DumpTestCase.php +++ b/tests/Database/Dumpers/DumpTestCase.php @@ -9,7 +9,6 @@ /** * Class DumpTestCase * - * @package Arcanedev\LaravelBackup\Tests\Database\Dumpers * @author ARCANEDEV */ abstract class DumpTestCase extends TestCase diff --git a/tests/Database/Dumpers/MongoDbDumperTest.php b/tests/Database/Dumpers/MongoDbDumperTest.php index 82e1ab1..3c7688a 100644 --- a/tests/Database/Dumpers/MongoDbDumperTest.php +++ b/tests/Database/Dumpers/MongoDbDumperTest.php @@ -11,7 +11,6 @@ /** * Class MongoDbDumperTest * - * @package Arcanedev\LaravelBackup\Tests\Database\Dumpers * @author ARCANEDEV */ class MongoDbDumperTest extends DumpTestCase diff --git a/tests/Database/Dumpers/MySqlDumperTest.php b/tests/Database/Dumpers/MySqlDumperTest.php index a9a367b..b88c2cc 100644 --- a/tests/Database/Dumpers/MySqlDumperTest.php +++ b/tests/Database/Dumpers/MySqlDumperTest.php @@ -6,13 +6,11 @@ use Arcanedev\LaravelBackup\Database\Compressors\GzipCompressor; use Arcanedev\LaravelBackup\Database\Dumpers\MySqlDumper; -use Arcanedev\LaravelBackup\Exceptions\CannotSetDatabaseParameter; -use Arcanedev\LaravelBackup\Exceptions\CannotStartDatabaseDump; +use Arcanedev\LaravelBackup\Exceptions\{CannotSetDatabaseParameter, CannotStartDatabaseDump}; /** * Class MySqlDumperTest * - * @package Arcanedev\LaravelBackup\Tests\Database\Dumpers * @author ARCANEDEV */ class MySqlDumperTest extends DumpTestCase diff --git a/tests/Database/Dumpers/PostgreSqlDumperTest.php b/tests/Database/Dumpers/PostgreSqlDumperTest.php index c439327..dc331cd 100644 --- a/tests/Database/Dumpers/PostgreSqlDumperTest.php +++ b/tests/Database/Dumpers/PostgreSqlDumperTest.php @@ -6,13 +6,11 @@ use Arcanedev\LaravelBackup\Database\Compressors\GzipCompressor; use Arcanedev\LaravelBackup\Database\Dumpers\PostgreSqlDumper; -use Arcanedev\LaravelBackup\Exceptions\CannotSetDatabaseParameter; -use Arcanedev\LaravelBackup\Exceptions\CannotStartDatabaseDump; +use Arcanedev\LaravelBackup\Exceptions\{CannotSetDatabaseParameter, CannotStartDatabaseDump}; /** * Class PostgreSqlDumperTest * - * @package Arcanedev\LaravelBackup\Tests\Database\Dumpers * @author ARCANEDEV */ class PostgreSqlDumperTest extends DumpTestCase diff --git a/tests/Database/Dumpers/SqliteDumperTest.php b/tests/Database/Dumpers/SqliteDumperTest.php index ebb0342..46a85ed 100644 --- a/tests/Database/Dumpers/SqliteDumperTest.php +++ b/tests/Database/Dumpers/SqliteDumperTest.php @@ -10,7 +10,6 @@ /** * Class SqliteDumperTest * - * @package Arcanedev\LaravelBackup\Tests\Database\Dumpers * @author ARCANEDEV */ class SqliteDumperTest extends DumpTestCase diff --git a/tests/Entities/BackupDestinationCollectionTest.php b/tests/Entities/BackupDestinationCollectionTest.php index 58ae237..354a93b 100644 --- a/tests/Entities/BackupDestinationCollectionTest.php +++ b/tests/Entities/BackupDestinationCollectionTest.php @@ -4,14 +4,12 @@ namespace Arcanedev\LaravelBackup\Tests\Entities; -use Arcanedev\LaravelBackup\Entities\BackupDestination; -use Arcanedev\LaravelBackup\Entities\BackupDestinationCollection; +use Arcanedev\LaravelBackup\Entities\{BackupDestination, BackupDestinationCollection}; use Arcanedev\LaravelBackup\Tests\TestCase; /** * Class BackupDestinationCollectionTest * - * @package Arcanedev\LaravelBackup\Tests\Entities * @author ARCANEDEV */ class BackupDestinationCollectionTest extends TestCase diff --git a/tests/Entities/BackupDestinationTest.php b/tests/Entities/BackupDestinationTest.php index 06f97b8..271c19b 100644 --- a/tests/Entities/BackupDestinationTest.php +++ b/tests/Entities/BackupDestinationTest.php @@ -4,9 +4,7 @@ namespace Arcanedev\LaravelBackup\Tests\Entities; -use Arcanedev\LaravelBackup\Entities\BackupCollection; -use Arcanedev\LaravelBackup\Entities\BackupDestination; -use Arcanedev\LaravelBackup\Entities\BackupDestinationCollection; +use Arcanedev\LaravelBackup\Entities\{BackupCollection, BackupDestination, BackupDestinationCollection}; use Arcanedev\LaravelBackup\Exceptions\InvalidBackupDestination; use Carbon\Carbon; use Illuminate\Filesystem\FilesystemAdapter; @@ -16,7 +14,6 @@ /** * Class BackupDestinationTest * - * @package Arcanedev\LaravelBackup\Tests\Entities * @author ARCANEDEV */ class BackupDestinationTest extends BackupTestCase diff --git a/tests/Entities/BackupTest.php b/tests/Entities/BackupTest.php index 3dd1720..fe4b14c 100644 --- a/tests/Entities/BackupTest.php +++ b/tests/Entities/BackupTest.php @@ -9,7 +9,6 @@ /** * Class BackupTest * - * @package Arcanedev\LaravelBackup\Tests\Entities * @author ARCANEDEV */ class BackupTest extends BackupTestCase diff --git a/tests/Entities/BackupTestCase.php b/tests/Entities/BackupTestCase.php index 4e19975..709a6c2 100644 --- a/tests/Entities/BackupTestCase.php +++ b/tests/Entities/BackupTestCase.php @@ -12,7 +12,6 @@ /** * Class BackupTestCase * - * @package Arcanedev\LaravelBackup\Tests\Entities * @author ARCANEDEV */ abstract class BackupTestCase extends TestCase diff --git a/tests/Entities/ManifestTest.php b/tests/Entities/ManifestTest.php index e9218e1..def2575 100644 --- a/tests/Entities/ManifestTest.php +++ b/tests/Entities/ManifestTest.php @@ -10,7 +10,6 @@ /** * Class ManifestTest * - * @package Arcanedev\LaravelBackup\Tests\Entities * @author ARCANEDEV */ class ManifestTest extends TestCase diff --git a/tests/EventSubscribers/BackupEventSubscriberTest.php b/tests/EventSubscribers/BackupEventSubscriberTest.php index 1c3f2eb..4d1c7af 100644 --- a/tests/EventSubscribers/BackupEventSubscriberTest.php +++ b/tests/EventSubscribers/BackupEventSubscriberTest.php @@ -5,8 +5,7 @@ namespace Arcanedev\LaravelBackup\Tests\EventSubscribers; use Arcanedev\LaravelBackup\Actions\Backup\BackupPassable; -use Arcanedev\LaravelBackup\Entities\BackupDestinationCollection; -use Arcanedev\LaravelBackup\Entities\Notifiable; +use Arcanedev\LaravelBackup\Entities\{BackupDestinationCollection, Notifiable}; use Arcanedev\LaravelBackup\Events\BackupActionHasFailed; use Arcanedev\LaravelBackup\Notifications\BackupHasFailedNotification; use Arcanedev\LaravelBackup\Tests\TestCase; @@ -16,7 +15,6 @@ /** * Class BackupEventSubscriberTest * - * @package Arcanedev\LaravelBackup\Tests\EventSubscribers * @author ARCANEDEV */ class BackupEventSubscriberTest extends TestCase diff --git a/tests/Helpers/FileSelectorTest.php b/tests/Helpers/FileSelectorTest.php index 1e9fbe4..15c6cf6 100644 --- a/tests/Helpers/FileSelectorTest.php +++ b/tests/Helpers/FileSelectorTest.php @@ -11,7 +11,6 @@ /** * Class FileSelectorTest * - * @package Arcanedev\LaravelBackup\Tests\Helpers * @author ARCANEDEV */ class FileSelectorTest extends TestCase diff --git a/tests/Helpers/FormatTest.php b/tests/Helpers/FormatTest.php index b013830..5a80d35 100644 --- a/tests/Helpers/FormatTest.php +++ b/tests/Helpers/FormatTest.php @@ -11,7 +11,6 @@ /** * Class FormatTest * - * @package Arcanedev\LaravelBackup\Tests\Helpers * @author ARCANEDEV */ class FormatTest extends TestCase diff --git a/tests/Helpers/ZipTest.php b/tests/Helpers/ZipTest.php index 2bd515b..ebf9e77 100644 --- a/tests/Helpers/ZipTest.php +++ b/tests/Helpers/ZipTest.php @@ -10,7 +10,6 @@ /** * Class ZipTest * - * @package Arcanedev\LaravelBackup\Tests\Helpers * @author ARCANEDEV */ class ZipTest extends TestCase diff --git a/tests/Providers/DeferredServiceProviderTest.php b/tests/Providers/DeferredServiceProviderTest.php index 2db7d56..bfdbfb5 100644 --- a/tests/Providers/DeferredServiceProviderTest.php +++ b/tests/Providers/DeferredServiceProviderTest.php @@ -12,7 +12,6 @@ /** * Class DeferredServiceProviderTest * - * @package Arcanedev\LaravelBackup\Tests\Providers * @author ARCANEDEV */ class DeferredServiceProviderTest extends TestCase diff --git a/tests/TestCase.php b/tests/TestCase.php index 5e0c131..0e7802a 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -14,7 +14,6 @@ /** * Class TestCase * - * @package Arcanedev\LaravelBackup\Tests * @author ARCANEDEV */ abstract class TestCase extends OrchestraTestCase