The backup 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/v4)  Taking-backups  The backup 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) 

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

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

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

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

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

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

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

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

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

 The backup process
==================

###  On this page 

1. [ 1. Ensuring that the source is reachable ](#content-1-ensuring-that-the-source-is-reachable)
2. [ 2. Ensuring that the destination is reachable ](#content-2-ensuring-that-the-destination-is-reachable)
3. [ 3. Determining the destination directory ](#content-3-determining-the-destination-directory)
4. [ 4. Perform pre-backup commands ](#content-4-perform-pre-backup-commands)
5. [ 5. Running the actual backup. ](#content-5-running-the-actual-backup)
6. [ 6. Perform post-backup commands ](#content-6-perform-post-backup-commands)
7. [ 7. Calculate backup size ](#content-7-calculate-backup-size)

When creating a backup, these steps will be performed.

1. Ensuring that the source is reachable
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The package will try to log in the source server and perform the `whoami` command. If that succeeds, the source is considered reachable. If that fails, the backup process will stop.

2. Ensuring that the destination is reachable
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The package will verify if the `disk_name` on the `Destination` matches a disk defined in `config/filesystems.php`. If the disk does not exist, the backup process will stop.

3. Determining the destination directory
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

On the destination disk a directory will be created with this format:

`/<source-id>/<backup-<date-in-YmdHis-format>`

If the source has a [`directory_name`](/docs/laravel-backup-server/v1/taking-backups/creating-a-source#content-naming-the-backup-directory), that is used instead of the source's id.

`/<source-directory-name>/<backup-<date-in-YmdHis-format>`

If that directory could not be created - you know the drill by now - the backup process will stop.

4. Perform pre-backup commands
------------------------------------------------------------------------------------------------------------------------------------------------

On a `Source` you can save an array with unix commands `pre_backup_commands`. These commands will now be executed on the source. You could add a command here to dump your database to the filesystem, so it will be backed up too.

If one of these commands fail, the backup process will stop.

5. Running the actual backup.
-------------------------------------------------------------------------------------------------------------------------------------------

Finally, we have arrived to the holy grail of this package: taking an actual backup. Under the hood, `rsync` is used to copy all files and directories specified in the `includes` array on the `Source`. Files and directories in the `excludes` array of the `Source` will be excluded.

If the backup isn't the initial one, than `rsync` will take in account the previous backup. Only files that are new or changed will be copied to the destination directory of the backup. Files that are identical to the ones in the previous backup, will not be copied. Instead, `rsync` will put a hard link to the file in the previous backup. This means that, even though a file will appear in your filesystem, no real disk space will be used.

When the previous backup will be deleted, the hard links will still work. The filesystem is smart enough to know that there is still an entry in the filesystem pointing to the space on the hard disk and the space will not be freed.

Should `rsync` fail, the backup process will stop

6. Perform post-backup commands
---------------------------------------------------------------------------------------------------------------------------------------------------

On a `Source` you can save an array with unix commands `post_backup_commands`. These commands will now be executed on the source. You could add a command here to delete and old db dumps from the filesystem.

If one of these commands fail, the backup process will stop.

7. Calculate backup size
------------------------------------------------------------------------------------------------------------------------------

The total size of the backup will now be calculated and save in the `size_in_kb` attribute on the `Source`. This size in the total if you were to copy all these files to another disk. On your backup disk it could be, due to the use of hard link, that the actually used space on disk is much lower.

You can increase the default timeout for this calculation with the `backup_size_calculation_timeout_in_seconds` value in the config file. This may be necessary for very large backups that take a long time to calculate the size of.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
