Laravel Forge JavaScript SDK

Backups

Backups

Database backups are only available on the Business plan.

Create a backup configuration

Method

forge.backups.createConfig(server_id, payload)

Usage

1const forge = new Forge('API_TOKEN');
2
3const backupConfig = await forge.backups.createConfig(server_id, payload);

Payload

1{
2 provider: 'spaces',
3 credentials: {
4 endpoint: 'https://my-endpoint.com',
5 region: 'region-key',
6 bucket: 'bucket-name',
7 access_key: '',
8 secret_key: ''
9 },
10 frequency: {
11 type: 'weekly',
12 time: '12:30',
13 day: 1
14 },
15 directory: 'backups/server/db',
16 email: 'forge@laravel.com',
17 retention: 7,
18 databases: [
19 24
20 ]
21}

Available Providers

KeyDescription
s3Amazon S3
spacesDigitalOcean Spaces
customCustom (S3 Compatible, e.g. MinIO)

When supplying a custom provider, you must also provide an endpoint.

Frequency options

  • hourly
  • daily - you must supply a time in 24 hour format
  • weekly - you must supply a time in 24 hour format and a day option 0 (Sunday) - 6 (Saturday)
  • custom - you must supply a custom value, as a valid cron expression

Example Response

1{
2 "backup": {
3 "id": 10,
4 "day_of_week": null,
5 "time": null,
6 "provider": "spaces",
7 "provider_name": "DigitalOcean Spaces",
8 "status": "installing",
9 "databases": [
10 {
11 "id": 24,
12 "name": "forge",
13 "status": "installed",
14 "created_at": "2020-01-13 15:47:33"
15 }
16 ],
17 "backups": [],
18 "last_backup_time": null
19 }
20}

List backup configurations

Method

forge.backups.listConfigs(server_id)

Usage

1const forge = new Forge('API_TOKEN');
2
3const backupConfigs = await forge.backups.listConfigs(server_id);

Example Response

1{
2 "backups": [
3 {
4 "id": 10,
5 "day_of_week": null,
6 "time": null,
7 "provider": "spaces",
8 "provider_name": "DigitalOcean Spaces",
9 "status": "installed",
10 "databases": [
11 {
12 "id": 100,
13 "name": "forge",
14 "status": "installed",
15 "created_at": "2020-01-01 10:00:00"
16 }
17 ],
18 "backups": [
19 {
20 "id": 144,
21 "backup_id": 10,
22 "status": "success",
23 "restore_status": null,
24 "archive_path": "s3://backup-configs/server/db/backup-10-20200101123601.tar.gz",
25 "duration": 4,
26 "date": "1st Jan 12:36 PM"
27 }
28 ],
29 "last_backup_time": "3 days ago"
30 }
31 ]
32}

Get a backup configuration

Method

forge.backups.getConfig(server_id, config_id)

Usage

1const forge = new Forge('API_TOKEN');
2
3const backupConfig = await forge.backups.getConfig(server_id, config_id);

Example Response

1{
2 "backup": {
3 "id": 10,
4 "day_of_week": null,
5 "time": null,
6 "provider": "spaces",
7 "provider_name": "DigitalOcean Spaces",
8 "status": "installed",
9 "databases": [
10 {
11 "id": 24,
12 "name": "forge",
13 "status": "installed",
14 "created_at": "2020-01-13 15:47:33"
15 }
16 ],
17 "backups": [],
18 "last_backup_time": null
19 }
20}

Update backup configuration

Method

forge.backups.updateConfig(server_id, config_id, payload)

Usage

1const forge = new Forge('API_TOKEN');
2
3const backupConfig = await forge.backups.updateConfig(
4 server_id,
5 config_id,
6 payload,
7);

Payload

{
provider: 'spaces',
credentials: {
endpoint: 'https://my-endpoint.com',
region: 'region-key',
bucket: 'bucket-name',
access_key: '',
secret_key: ''
},
frequency: {
type: 'weekly',
time: '12:30',
day: 1
},
directory: 'backups/server/db',
email: 'forge@laravel.com',
retention: 7
}

The payload and options are the same for updating as they are for creating.

Note: You cannot change the databases to backup of an existing backup configuration.

Example Response

1{
2 "backup": {
3 "id": 10,
4 "day_of_week": null,
5 "time": null,
6 "provider": "spaces",
7 "provider_name": "DigitalOcean Spaces",
8 "status": "updating",
9 "databases": [
10 {
11 "id": 24,
12 "name": "forge",
13 "status": "installed",
14 "created_at": "2020-01-13 15:47:33"
15 }
16 ],
17 "backups": [],
18 "last_backup_time": null
19 }
20}

Delete backup configuration

Method

forge.backups.deleteConfig(server_id, config_id)

Usage

1const forge = new Forge('API_TOKEN');
2
3await forge.backups.deleteConfig(server_id, config_id);

Manually run backup configuration

Method

forge.backups.runConfig(server_id, config_id)

Usage

1const forge = new Forge('API_TOKEN');
2
3await forge.backups.runConfig(server_id, config_id);

Restore a backup

Method

forge.backups.restore(server_id, config_id, backup_id, payload)

Usage

1const forge = new Forge('API_TOKEN');
2
3await forge.backups.restore(server_id, config_id, backup_id, payload);

Payload

1{
2 database: 7;
3}

If no database value is provided, Forge will restore the first database available.


Delete a backup

Method

forge.backups.delete(server_id, config_id, backup_id)

Usage

1const forge = new Forge('API_TOKEN');
2
3await forge.backups.delete(server_id, config_id, backup_id);

Edit this page on GitHub