The clean up process | laravel-backup-server | Spatie

 SPATIE

  Laravel Backup Server
========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-backup-server](https://spatie.be/docs/laravel-backup-server/v3)  Cleaning-up-backups  The clean up process

 Version   v4   v3   v2   v1

 Other versions for crawler [v4](https://spatie.be/docs/laravel-backup-server/v4) [v3](https://spatie.be/docs/laravel-backup-server/v3) [v2](https://spatie.be/docs/laravel-backup-server/v2) [v1](https://spatie.be/docs/laravel-backup-server/v1)

- [ Introduction ](https://spatie.be/docs/laravel-backup-server/v3/introduction)
- [ Getting a license ](https://spatie.be/docs/laravel-backup-server/v3/getting-a-license)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-backup-server/v3/installation-setup)
- [ Requirements ](https://spatie.be/docs/laravel-backup-server/v3/requirements)
- [ Upgrading ](https://spatie.be/docs/laravel-backup-server/v3/upgrading)
- [ Questions and issues ](https://spatie.be/docs/laravel-backup-server/v3/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-backup-server/v3/changelog)
- [ About us ](https://spatie.be/docs/laravel-backup-server/v3/about-us)
- [ License ](https://spatie.be/docs/laravel-backup-server/v3/license)

Taking backups
--------------

- [ Creating a destination ](https://spatie.be/docs/laravel-backup-server/v3/taking-backups/creating-a-destination)
- [ Creating a source ](https://spatie.be/docs/laravel-backup-server/v3/taking-backups/creating-a-source)
- [ Taking backups ](https://spatie.be/docs/laravel-backup-server/v3/taking-backups/taking-backups)
- [ The backup process ](https://spatie.be/docs/laravel-backup-server/v3/taking-backups/the-backup-process)
- [ Events ](https://spatie.be/docs/laravel-backup-server/v3/taking-backups/events)
- [ Listing sources and destinations ](https://spatie.be/docs/laravel-backup-server/v3/taking-backups/listing-sources-and-destinations)
- [ Working with backups ](https://spatie.be/docs/laravel-backup-server/v3/taking-backups/working-with-backups)
- [ Creating database backups ](https://spatie.be/docs/laravel-backup-server/v3/taking-backups/creating-database-backups)

Cleaning up backups
-------------------

- [ The clean up process ](https://spatie.be/docs/laravel-backup-server/v3/cleaning-up-backups/the-cleanup-process)
- [ Determining old backups ](https://spatie.be/docs/laravel-backup-server/v3/cleaning-up-backups/determining-old-backups)
- [ Events ](https://spatie.be/docs/laravel-backup-server/v3/cleaning-up-backups/events)

Monitoring the health of all backups
------------------------------------

- [ The monitoring process ](https://spatie.be/docs/laravel-backup-server/v3/monitoring-the-health-of-all-backups/the-monitoring-process)
- [ Checking health of sources ](https://spatie.be/docs/laravel-backup-server/v3/monitoring-the-health-of-all-backups/checking-health-of-sources)
- [ Checking health of destinations ](https://spatie.be/docs/laravel-backup-server/v3/monitoring-the-health-of-all-backups/checking-health-of-destinations)
- [ Events ](https://spatie.be/docs/laravel-backup-server/v3/monitoring-the-health-of-all-backups/events)

Sending notifications
---------------------

- [ Sending notifications ](https://spatie.be/docs/laravel-backup-server/v3/sending-notifications/sending-notifications)
- [ Adding extra notification channels ](https://spatie.be/docs/laravel-backup-server/v3/sending-notifications/adding-extra-notification-channels)
- [ Customizing the notifiable ](https://spatie.be/docs/laravel-backup-server/v3/sending-notifications/customizing-the-notifiable)

      You are viewing the documentation for **an older version** of this package. You can check the version you are using with the following command:

 `                                    composer show spatie/laravel-backup-server                                                                                                                                                                                                                                    `

The clean up process
====================

###  On this page

1. [ What happens during cleanup ](#content-what-happens-during-cleanup)
2. [ Cleaning up a source ](#content-cleaning-up-a-source)
3. [ Cleaning up a destination ](#content-cleaning-up-a-destination)
4. [ Removing a source ](#content-removing-a-source)

Over time the number of backups and the storage required to store them will grow. At some point you will want to clean up backups.

To clean up all backups this artisan command can be performed:

```
php artisan backup-server:cleanup
```

As mentioned in [the installation instructions](/docs/laravel-backup-server/v3/installation-setup), we recommend scheduling this command to run daily.

What happens during cleanup
-----------------------------------------------------------------------------------------------------------------------------------------

First, for each separate source, a clean up job to [clean up the source](docs/laravel-backup-server/v3/cleaning-up-backups/the-cleanup-process) will be dispatched. After that, for each separate destination, a clean up job to [clean up the destination](docs/laravel-backup-server/v1/cleaning-up-backups/the-cleanup-process) will be dispatched.

Cleaning up a source
--------------------------------------------------------------------------------------------------------------------

These steps will be performed when cleaning up a source

1. First, all `Backup` models that do not have a directory on the filesystem will be deleted.
2. Next old backups will be deleted. You can read more on we determine that a backup is "old" [in this section](/docs/laravel-backup-server/v3/cleaning-up-backups/determining-old-backups).
3. All backups that are mark as failed (their [backup process](/docs/laravel-backup-server/v3/taking-backups/the-backup-process) didn't complete fully) and are older than a day will be deleted.
4. Real backup size will be calculated. Because of the use of hard links in [the backup process](/docs/laravel-backup-server/v3/taking-backups/the-backup-process), the size of a backup will not match the size it actually takes on disk. Here, we are going to calculate what the real disk space usage is for each backup and save it in the `real_size_in_kb` on each `Backup`.

You can increase the default timeout for this calculation with the `backup_collection_size_calculation_timeout_in_seconds` value in the config file. This may be necessary for large backups, especially if you're backing up to a cloud volume.

Cleaning up a destination
-----------------------------------------------------------------------------------------------------------------------------------

The package will delete any directory on the destination that does not belong to one of the backups on it.

Removing a source
-----------------------------------------------------------------------------------------------------------

When you no longer need to support a source and want to remove all backups, the cleanup command will take care of it. You can remove the source record in the `backup_server_sources` table and execute the cleanup job.
