# ServerBackupEvent events

> 5 FeatherPanel plugin events on ServerBackupEvent (3 emitted by the core): the event names, the arguments each listener gets, where they fire and a PHP listener for each.

Source: https://featherpanel.com/docs/plugins/events/server-backup/

Part of the [plugin events reference](https://featherpanel.com/docs/plugins/events/). Listeners get the payload values as positional arguments in the order shown, cannot cancel the action, and must catch their own exceptions. 2 of these events are declared but no code emits them yet; they are marked not emitted.

## Setup

Import `ServerBackupEvent` in your entry class and register listeners in `processEvents()`:

```php
<?php

namespace App\Addons\myplugin;

use App\App;
use App\Plugins\AppPlugin;
use App\Plugins\PluginEvents;
use App\Plugins\Events\Events\ServerBackupEvent;

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(ServerBackupEvent::onServerBackupCreated(), function ($userUuid, $serverUuid, $backupUuid, ...$rest): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:backup:created');
        });
    }

    public static function pluginInstall(): void
    {
    }

    public static function pluginUninstall(): void
    {
    }
}
```

## `ServerBackupEvent::onServerBackupCreated()`

- Name: `featherpanel:user:server:backup:created`
- emitted at 3 sites
- 3 payload shapes
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerBackupEvent.php#L28)

Docblock: string server uuid, array backup data. (the emitter passes 3 values, see the table)

Same event name as `ServerEvent::onServerBackupCreated()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | not declared |
| 2 | `server_uuid` | `$serverUuid` | not declared |
| 3 | `backup_uuid` | `$backupUuid` | not declared |

| Arguments passed | Emitted from |
| --- | --- |
| `user_uuid`, `server_uuid`, `backup_uuid` | 
`ServerBackupController::createBackup`

 |
| `user_uuid`, `server_uuid`, `backup_uuid`, `type` | 

`ServerBackupController::createFullBackup`

 |
| `user_uuid`, `server_uuid`, `backup_uuid`, `backup_data` | 

`CreateBackupTool::execute`

 |

When it fires (3 sites)

-   [`ServerBackupController::createBackup`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/ServerBackupController.php#L537)[`POST /api/user/servers/{uuidShort}/backups`](https://featherpanel.com/docs/api/reference/user/server/backups/#post-user-servers-uuidShort-backups)
-   [`ServerBackupController::createFullBackup`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/ServerBackupController.php#L1758)
-   [`CreateBackupTool::execute`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Services/Chatbot/Tools/CreateBackupTool.php#L240)

```php
$event->on(ServerBackupEvent::onServerBackupCreated(), function ($userUuid, $serverUuid, $backupUuid, ...$rest): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:backup:created');
});
```

## `ServerBackupEvent::onServerBackupDeleted()`

- Name: `featherpanel:user:server:backup:deleted`
- emitted at 3 sites
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerBackupEvent.php#L36)

Docblock: string server uuid, string backup uuid. (the emitter passes 3 values, see the table)

Same event name as `ServerEvent::onServerBackupDeleted()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | not declared |
| 2 | `server_uuid` | `$serverUuid` | not declared |
| 3 | `backup_uuid` | `$backupUuid` | `string` |

When it fires (3 sites)

-   [`ServerBackupController::deleteBackup`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/ServerBackupController.php#L1187)[`DELETE /api/user/servers/{uuidShort}/backups/{backupUuid}`](https://featherpanel.com/docs/api/reference/user/server/backups/#delete-user-servers-uuidShort-backups-backupUuid)
-   [`ServerBackupController::bulkDeleteBackups`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/ServerBackupController.php#L1379)[`DELETE /api/user/servers/{uuidShort}/backups/bulk-delete`](https://featherpanel.com/docs/api/reference/user/server/backups/#delete-user-servers-uuidShort-backups-bulk-delete)
-   [`DeleteBackupTool::execute`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Services/Chatbot/Tools/DeleteBackupTool.php#L207)

```php
$event->on(ServerBackupEvent::onServerBackupDeleted(), function ($userUuid, $serverUuid, $backupUuid): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:backup:deleted ' . json_encode(['backup_uuid' => $backupUuid]));
});
```

## `ServerBackupEvent::onServerBackupDownloaded()`

- Name: `featherpanel:user:server:backup:downloaded`
- not emitted
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerBackupEvent.php#L44)

Docblock: string server uuid, string backup uuid, string download url.

```php
$event->on(ServerBackupEvent::onServerBackupDownloaded(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:backup:downloaded ' . json_encode($args));
});
```

No code emits this event yet, so the arguments are unknown. The listener accepts any.

## `ServerBackupEvent::onServerBackupError()`

- Name: `featherpanel:user:server:backup:error`
- not emitted
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerBackupEvent.php#L61)

Docblock: string error message, array context.

```php
$event->on(ServerBackupEvent::onServerBackupError(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:backup:error ' . json_encode($args));
});
```

No code emits this event yet, so the arguments are unknown. The listener accepts any.

## `ServerBackupEvent::onServerBackupRestored()`

- Name: `featherpanel:user:server:backup:restored`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerBackupEvent.php#L52)

Docblock: string server uuid, string backup uuid. (the emitter passes 3 values, see the table)

Same event name as `ServerEvent::onServerBackupRestored()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | not declared |
| 2 | `server_uuid` | `$serverUuid` | not declared |
| 3 | `backup_uuid` | `$backupUuid` | `string` |

When it fires (1 site)

-   [`ServerBackupController::restoreBackup`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/ServerBackupController.php#L821)[`POST /api/user/servers/{uuidShort}/backups/{backupUuid}/restore`](https://featherpanel.com/docs/api/reference/user/server/backups/#post-user-servers-uuidShort-backups-backupUuid-restore)

```php
$event->on(ServerBackupEvent::onServerBackupRestored(), function ($userUuid, $serverUuid, $backupUuid): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:backup:restored ' . json_encode(['backup_uuid' => $backupUuid]));
});
```
