Taking backups | laravel-backup-rust | Spatie       

 SPATIE  

laravel-backup-rust
===================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-backup-rust](https://spatie.be/docs/laravel-backup-rust/v1)  Taking-backups  Taking backups

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-backup-rust/v1) 

  Taking backups    
- [ Introduction ](https://spatie.be/docs/laravel-backup-rust/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-backup-rust/v1/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-backup-rust/v1/requirements)
- [ High level overview ](https://spatie.be/docs/laravel-backup-rust/v1/high-level-overview)
- [ Installation and setup ](https://spatie.be/docs/laravel-backup-rust/v1/installation-and-setup)
- [ Questions &amp; issues ](https://spatie.be/docs/laravel-backup-rust/v1/questions-and-issues)
- [ Changelog ](https://spatie.be/docs/laravel-backup-rust/v1/changelog)
- [ About us ](https://spatie.be/docs/laravel-backup-rust/v1/about-us)
- [ Testing ](https://spatie.be/docs/laravel-backup-rust/v1/testing)

Taking Backups
--------------

- [ Taking backups ](https://spatie.be/docs/laravel-backup-rust/v1/taking-backups/overview)
- [ Events ](https://spatie.be/docs/laravel-backup-rust/v1/taking-backups/events)

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

- [ Cleaning up old backups ](https://spatie.be/docs/laravel-backup-rust/v1/cleaning-up-old-backups/overview)
- [ Events ](https://spatie.be/docs/laravel-backup-rust/v1/cleaning-up-old-backups/events)

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

- [ Monitoring the health of all backups ](https://spatie.be/docs/laravel-backup-rust/v1/monitoring-the-health-of-all-backups/overview)
- [ Creating your custom health check ](https://spatie.be/docs/laravel-backup-rust/v1/monitoring-the-health-of-all-backups/creating-your-custom-health-check)
- [ Events ](https://spatie.be/docs/laravel-backup-rust/v1/monitoring-the-health-of-all-backups/events)

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

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

Advanced Usage
--------------

- [ Adding extra files to a backup ](https://spatie.be/docs/laravel-backup-rust/v1/advanced-usage/adding-extra-files-to-a-backup)
- [ Backing up a non-laravel application ](https://spatie.be/docs/laravel-backup-rust/v1/advanced-usage/backing-up-a-non-laravel-application)
- [ Binary database dumps with PostgreSQL ](https://spatie.be/docs/laravel-backup-rust/v1/advanced-usage/binary-database-dumps-with-postgresql)
- [ Encrypt backup archives ](https://spatie.be/docs/laravel-backup-rust/v1/advanced-usage/encrypt-backup-archives)
- [ Isolated mode ](https://spatie.be/docs/laravel-backup-rust/v1/advanced-usage/isolated-mode)

 Taking backups
==============

###  On this page 

1. [ Run a backup ](#content-run-a-backup)
2. [ Choose sources and destinations ](#content-choose-sources-and-destinations)
3. [ Publication and failures ](#content-publication-and-failures)

Run a backup
--------------------------------------------------------------------------------------------

- Use your application's `backup:run` console command, or the bundled binary shown below.
- Install the native database dump tools before running a database backup.
- Select configured disks and connection names. Package JSON files configure policy, not Laravel's disk or connection definitions.

```
cargo run -- backup:run
cargo run -- backup:run --only-to-disk=backups
cargo run -- backup:run --only-db --db-name=sqlite
cargo run -- backup:run --only-files
```

- Monitoring does not distinguish partial archives from full backups. Keep partial backups in a separate backup directory if you monitor both.
- Archives default to `<backup.name>/<YYYY-MM-DD-HH-MM-SS>.zip` using `backup.timezone`.
- Override the filename, suffix, directory or source exclusions for a single run:

```
cargo run -- backup:run --filename=my-backup.zip
cargo run -- backup:run --filename-suffix=extra
cargo run -- backup:run --destination-path=custom/path
cargo run -- backup:run --exclude=storage/logs --exclude=storage/debugbar
```

- Filenames must be ZIP basenames. Destination directories must be relative logical paths without `.` or `..` components.
- Source and exclusion paths resolve against `config.app.base_path` when commands execute.
- Timeouts use seconds. Cancellation and timeouts are checked between files, inside file-copy loops and before publication; native dump processes receive a timeout too.
- Configure retry attempts or suppress notification delivery without disabling events:

```
cargo run -- backup:run --timeout=600 --tries=3
cargo run -- backup:run --disable-notifications
cargo run -- backup:run --config=config/backup_uploads.json
```

Choose sources and destinations
-----------------------------------------------------------------------------------------------------------------------------------------------------

- Include files, directories or glob patterns in `source.files.include`.
- Exclude paths and their descendants in `source.files.exclude`. Temporary backup directories and local backup destinations are excluded automatically.
- Symbolic links are not followed by default. Permission errors fail the backup unless unreadable directories are explicitly ignored; symlink cycles and other traversal errors still fail.
- `relative_path` strips a directory prefix from entry names. `None` uses absolute path components without the filesystem root or drive prefix.
- Database names refer to Laravel connections. The provider defaults to the application's default connection.
- Configure remote disks in Laravel, then add their names to `destination.disks`. Keep at least one backup away from the application host.

```
use spatie_backup::Config;

let mut config = Config::default();
config.backup.name = "invoices".into();
config.backup.source.files.include = vec!["app".into(), "storage/uploads".into()];
config.backup.source.files.exclude = vec!["storage/logs".into()];
config.backup.source.files.relative_path = Some(".".into());
config.backup.source.databases = vec!["sqlite".into()];
config.backup.destination.disks = vec!["local".into(), "offsite".into()];
config.backup.verify_backup = true;
```

Publication and failures
--------------------------------------------------------------------------------------------------------------------------------

- The job creates dumps and a ZIP in a unique temporary directory, then streams the ZIP to each disk.
- Temporary files are removed when the job returns, including on error. Allow enough local disk space for both dumps and the archive.
- `verify_backup = true` reads each entry before publication to check decryption, integrity and entry count.
- Destination writes fail fast by default. Set `destination.continue_on_failure = true` to try every disk and report individual failures. At least one disk must succeed.
- `Error::Destination` identifies a failed disk and retains the underlying error. `Error::NoSuccessfulDestination` means all attempted disks failed with continuation enabled.
- A failed run does not roll back archives already published to other disks. A timeout is not an atomic rollback of in-flight storage writes.
- Configure [notifications](../sending-notifications/overview) and test restoring your backups regularly.

 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)
