Installation and setup | 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)  Installation and setup

 Version   v1      

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

  Installation and setup    
- [ 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)

 Installation and setup
======================

###  On this page 

1. [ Basic installation ](#content-basic-installation)
2. [ Configuring backup settings ](#content-configuring-backup-settings)
3. [ Scheduling ](#content-scheduling)
4. [ Dumping the database ](#content-dumping-the-database)
5. [ Monitoring and notifications ](#content-monitoring-and-notifications)

Basic installation
--------------------------------------------------------------------------------------------------------------

- Add the public Git dependency. The package is not distributed through crates.io.

```
[dependencies]
laravel = { package = "laravel-rust", version = "=0.1.0", default-features = false, features = ["database-sqlite"] }
spatie-laravel-backup = { git = "https://github.com/spatie/laravel-backup-rust" }
```

- Register `service_provider()` in `Application::configure().with_providers(...)`. It uses package tools to install the `spatie_backup::Config` section, a transient container-managed `tokio::sync::Mutex<BackupManager>` and the four backup commands.
- Edit the registered section with `section_mut::<Config>()` in `with_config` to preserve environment-backed defaults. Package tools is a pinned public Git dependency.

```
use laravel::config::{database::ConnectionConfig, filesystems::LocalDisk};
use spatie_backup::{service_provider, Config};

let app = laravel::Application::configure()
    .with_providers(|providers| { providers.add(service_provider()); })
    .with_config(|config, _| {
        config.database.default = "sqlite".into();
        config.database.add_connection("sqlite", ConnectionConfig::new("sqlite://database/app.sqlite?mode=rwc"));
        config.filesystems.add_disk("backups", LocalDisk::new("storage/backups"));
        let backup = config.section_mut::<Config>();
        backup.backup.source.databases = vec!["sqlite".into()];
        backup.backup.source.files.include = vec!["app".into(), "database".into()];
        backup.backup.destination.disks = vec!["backups".into()];
        backup.monitor_backups[0].disks = vec!["backups".into()];
    })
    .create();
```

- Use `.run()` instead of `.create()` in your application's `main` to start its console/HTTP entry point. Constructing the application does not create or dump a database.

Configuring backup settings
-----------------------------------------------------------------------------------------------------------------------------------------

- `Config::default()` contains the complete package defaults. Generate an environment-backed JSON copy with `cargo run --example config > backup.json`.
- The file contains backup policy and connection/disk names, not database credentials or disk definitions. It includes `BACKUP_ARCHIVE_PASSWORD` when set; keep the generated file out of version control.
- Unknown keys fail. Set source paths, destination disks, monitored disks, retention and notification recipients before using it.
- `--config path.json` loads an alternate package config for one command. It does not mutate Laravel's config repository or replace its connection/storage definitions.
- For the bundled binary, `BACKUP_CONFIG` optionally loads this package section at startup.
- Source includes, exclusions, relative archive paths and temporary directories resolve against `config.app.base_path`. CLI `--exclude` paths use that same root.
- The provider reads `APP_NAME` for the backup and monitored-backup name, the application's name/environment for notification text, its default database connection, and `BACKUP_ARCHIVE_PASSWORD`.
- Laravel's mail config supplies the sender unless `notifications.mail.from` overrides it.
- `log_enabled = false` disables backup activity messages. Otherwise they use the `spatie_backup` tracing target and Laravel's configured logging sinks; no separate logger is installed.
- Laravel's standalone defaults read `DB_CONNECTION`, `DATABASE_URL` and its normal filesystem/mail/cache environment variables. Use application config for additional disks/connections.
- The default local disk is `storage/app/private`, so a backup named `laravel-backup` lands in `storage/app/private/laravel-backup`.
- SQLite paths resolve against `config.app.base_path`; in-memory SQLite cannot be dumped by a separate process.

Scheduling
--------------------------------------------------------------------------------------

- Register commands with Laravel's scheduler:

```
let app = laravel::Application::configure()
    .with_providers(|providers| { providers.add(spatie_backup::service_provider()); })
    .with_schedule(|schedule, _| {
        schedule.command("backup:clean --isolated").daily_at("01:00");
        schedule.command("backup:run --isolated").daily_at("01:30");
        schedule.command("backup:monitor").daily_at("03:00");
    })
    .create();
```

- Run the application's `schedule:run` command every minute under your process supervisor or cron. Missed runs and host supervision are not managed by this package.
- Use a shared Laravel cache store for `--isolated` across processes. Its default memory cache is not a distributed lock.

Dumping the database
--------------------------------------------------------------------------------------------------------------------

- The manager imports configured Laravel connection URLs and typed driver options. It selects the first read endpoint when present, otherwise the writer.
- Native tools do not share a SQLx transaction, initialization SQL or sticky-session state. SQLite files, including typed SQLite filenames, resolve against the application's base directory.
- Configure native tool options in `Lifecycle::dumping_database`. Keep the normal `EventHandler` when adding hooks:

```
use spatie_backup::{Lifecycle, Result, notifications::EventHandler};

struct DumpOptions;
#[async_trait::async_trait]
impl Lifecycle for DumpOptions {
    fn dumping_database(&self, _: &str, dumper: &mut spatie_db_dumper::DbDumper) -> Result<()> {
        *dumper = dumper.clone().exclude_tables(["sessions", "cache"]);
        Ok(())
    }
}
let mut events = EventHandler::new(Default::default());
events.hooks = std::sync::Arc::new(DumpOptions);
// Assign Arc::new(events) to your resolved BackupManager's lifecycle.
```

- To apply these hooks to console commands, replace the transient binding in `with_services`. Resolving and mutating a separate manager does not affect a later command:

```
use spatie_backup::{commands::BackupManager, notifications::EventHandler};
use tokio::sync::Mutex;
    .with_providers(|providers| { providers.add(spatie_backup::service_provider()); })
    .with_services(|services| {
        services.bind(async |_| {
            let mut manager = BackupManager::from_framework()?;
            let events = EventHandler::new(manager.config.notifications.clone());
            // Set events.hooks and events.notifications here.
            manager.lifecycle = std::sync::Arc::new(events);
            // Set manager.cleanup_strategy, checks or dumpers here.
            Ok(Mutex::new(manager))
        });
    })
```

- Native dump execution runs on Tokio's blocking pool. Configure the dumper's timeout and tool-specific options in the hook. Extra options are literal arguments, never shell commands.
- Commands wait for backup and cleanup to finish. Application-owned Laravel jobs can invoke the public manager and select their own queue options.

Monitoring and notifications
--------------------------------------------------------------------------------------------------------------------------------------------

- Use a separate monitoring host when possible, so a broken application cannot hide its missing backups. See [monitoring](monitoring-the-health-of-all-backups/overview) and [notifications](sending-notifications/overview).

 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)
