Creating a source | 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/v2)  Taking-backups  Creating a source

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

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

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

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

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

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

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

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

- [ Sending notifications ](https://spatie.be/docs/laravel-backup-server/v2/sending-notifications/sending-notifications)
- [ Adding extra notification channels ](https://spatie.be/docs/laravel-backup-server/v2/sending-notifications/adding-extra-notification-channels)
- [ Customizing the notifiable ](https://spatie.be/docs/laravel-backup-server/v2/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                                                                                                                                                                                                                                    `

Creating a source
=================

The collection of files on a remote server that you wish to backup is represented by a `Source`.

A `Source` is an Eloquent model. It can be created like this.

```
Destinations\BackupServer\Models\Source::create($attributes)
```

These attributes can be set

- `name` (required): the name of the host, you can name it anything you'd like
- `host` (required): the hostname of the server you wish to backup
- `ssh_user`: the user name to use to ssh into the source server
- `ssh_port`: the port to use when connecting to the source server
- `ssh_private_key_file`: the path to a ssh key file to use when connecting to the source server
- `destination_id`: the id of the [destination](/docs/laravel-backup-server/v1/taking-backups/creating-a-destination) you wish to backup to
- `cron_expression` (required): the cron expression on which `backup-server:dispatch-backups` should create backups for this source
- `includes`: an array of paths you wish to backup. These can be relative to the home directory of the ssh user, or absolute
- `excludes`: an array of paths you wish to exclude from the backup. These should be relative to the paths giving in `includes`
- `pre_backup_commands`: an array of commands that should be executed on the source server prior to backing up. You could use this to dump the database to the filesystem.
- `post_backup_commands`: an array of commands that should be executed on the source server after the backup is complete. You could use this to clean databases that have been dumped to the filesystem.

The other attributes on the destination are used for [monitoring health](docs/laravel-backup-server/v1/monitoring-the-health-of-all-backups/the-monitoring-process) and [clean up](/docs/laravel-backup-server/v1/cleaning-up-backups/the-cleanup-process) of backups.
