spatie / laravel-backup

A package to backup your Laravel app
https://spatie.be/docs/laravel-backup
MIT License
5.66k stars 762 forks source link

Backup's being cleaned without following policy #317

Closed JoshMountain closed 8 years ago

JoshMountain commented 8 years ago

@freekmurze as a follow-up to my tweet, here is a copy of my config. I am trying to have the system store exactly 90 daily backups and nothing else. On the 91st day the oldest backup would be cleaned.

<?php

return [

    'backup' => [

        /*
         * The name of this application. You can use this name to monitor
         * the backups.
         */
        'name' => 'project-name',

        'source' => [

            'files' => [

                /*
                 * The list of directories that should be part of the backup. You can
                 * specify individual files as well.
                 */
                'include' => [
                    base_path(),
                ],

                /*
                 * These directories will be excluded from the backup.
                 * You can specify individual files as well.
                 */
                'exclude' => [
                    base_path('vendor'),
                    base_path('node_modules'),
                    storage_path(),
                ],

                /*
                 * Determines if symlinks should be followed.
                 */
                'followLinks' => false,
            ],

            /*
             * The names of the connections to the databases that should be part of the backup.
             * Currently only MySQL- and PostgreSQL-databases are supported.
             */
            'databases' => [
                'mysql',
            ],
        ],

        'destination' => [

            /*
             * The disk names on which the backups will be stored.
             */
            'disks' => [
                'sftp',
            ],
        ],
    ],

    'cleanup' => [
        /*
         * The strategy that will be used to cleanup old backups.
         * The youngest backup will never be deleted.
         */
        'strategy' => \Spatie\Backup\Tasks\Cleanup\Strategies\DefaultStrategy::class,

        'defaultStrategy' => [

            /*
             * The amount of days that all backups must be kept.
             */
            'keepAllBackupsForDays' => 90,

            /*
             * The amount of days that all daily backups must be kept.
             */
            'keepDailyBackupsForDays' => 90,

            /*
             * The amount of weeks of which one weekly backup must be kept.
             */
            'keepWeeklyBackupsForWeeks' => 0,

            /*
             * The amount of months of which one monthly backup must be kept.
             */
            'keepMonthlyBackupsForMonths' => 0,

            /*
             * The amount of years of which one yearly backup must be kept.
             */
            'keepYearlyBackupsForYears' => 0,

            /*
             * After cleaning up the backups remove the oldest backup until
             * this amount of megabytes has been reached.
             */
            //'deleteOldestBackupsWhenUsingMoreMegabytesThan' => 5000,
        ],
    ],

    /*
     *  In this array 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' => 'project-name',
            'disks' => ['sftp'],
            'newestBackupsShouldNotBeOlderThanDays' => 90,
            //'storageUsedMayNotBeHigherThanMegabytes' => 5000,
        ],

        /*
        [
            'name' => 'name of the second app',
            'disks' => ['local', 's3'],
            'newestBackupsShouldNotBeOlderThanDays' => 1,
            'storageUsedMayNotBeHigherThanMegabytes' => 5000,
        ],
        */
    ],

    'notifications' => [

        /*
         * This class will be used to send all notifications.
         */
        'handler' => Spatie\Backup\Notifications\Notifier::class,

        /*
         * Here you can specify the ways you want to be notified when certain
         * events take place. Possible values are "log", "mail", "slack",
         * "pushover", and "telegram".
         *
         * Slack requires the installation of the maknz/slack package.
         * Telegram requires the installation of the irazasyed/telegram-bot-sdk package.
         */
        'events' => [
            'whenBackupWasSuccessful'     => ['log'],
            'whenCleanupWasSuccessful'    => ['log'],
            'whenHealthyBackupWasFound'   => ['log'],
            'whenBackupHasFailed'         => ['log', 'mail'],
            'whenCleanupHasFailed'        => ['log', 'mail'],
            'whenUnhealthyBackupWasFound' => ['log', 'mail'],
        ],

        /*
         * Here you can specify how emails should be sent.
         */
        'mail' => [
            'from' => 'me@example.com',
            'to'   => 'me@example.com',
        ],

        /*
         * Here you can specify how messages should be sent to Slack.
         */
        // 'slack' => [
        //     'channel'  => '#backups',
        //     'username' => 'Backup bot',
        //     'icon'     => ':robot:',
        // ],

        /*
         * Here you can specify how messages should be sent to Pushover.
         */
        // 'pushover' => [
        //     'token'  => env('PUSHOVER_APP_TOKEN'),
        //     'user'   => env('PUSHOVER_USER_KEY'),
        //     'sounds' => [
        //         'success' => env('PUSHOVER_SOUND_SUCCESS', 'pushover'),
        //         'error'   => env('PUSHOVER_SOUND_ERROR', 'siren'),
        //     ],
        // ],

        /*
         * Here you can specify how messages should be sent to Telegram Bot API.
         */
        // 'telegram' => [
        //     'bot_token' => env('TELEGRAM_BOT_TOKEN'),
        //     'chat_id'   => env('TELEGRAM_CHAT_ID'),
        //     'async_requests' => env('TELEGRAM_ASYNC_REQUESTS', false),
        //     'disable_web_page_preview' => env('TELEGRAM_DISABLE_WEB_PAGE_PREVIEW', true),
        // ],
    ],
];
freekmurze commented 8 years ago

I can't seem to reproduce this. Are you sure the backups are being made in the first place?

JoshMountain commented 8 years ago

@freekmurze Yeah, I can run php artisan backup:run manually and it will generate a backup and send it to the remote storage like so:

screen shot 2016-11-30 at 4 43 21 pm

but when I run php artisan backup:clean I get this:

screen shot 2016-11-30 at 4

freekmurze commented 8 years ago

Which version of the package are you using?

JoshMountain commented 8 years ago

3.10.2 in that project

freekmurze commented 8 years ago

The line with deleteOldestBackupsWhenUsingMoreMegabytesThan is commented. I'm thinking that the package now interprets that value as being 0, so it will cleanup everything except the youngest backup.

Try uncommenting that line.

JoshMountain commented 8 years ago

That solved the issue, thank you!!

freekmurze commented 8 years ago

👍