Goal
Re-create a deployment target or worker that was deleted by mistake (or by a machine policy cleanup), using the configuration Octopus recorded in the audit log. This applies to self-hosted Octopus Server and Octopus Cloud. The steps for finding archived events apply to Octopus 2023.3 and later.
Octopus doesn't have an undo or restore option for deleted deployment targets or workers. When either is deleted, though, Octopus records an audit event that includes its settings as they were at the time of deletion. You can read those settings in the audit log and use them to add the target or worker again in the Octopus Web Portal.
[!WARNING]
The re-created target or worker gets a new ID (for example,Machines-142instead ofMachines-87, orWorkers-31instead ofWorkers-12). Deployment history, task logs, and audit events stay linked to the old ID, so they won't appear on the new record's page. Anything that references the old ID, such as a script or a Terraform state file, needs updating.
Prerequisites
- EventView permission in the space that contained the target or worker, so you can read the audit log.
- Permission to add the record in that space:
- For a deployment target, MachineCreate, plus access to the target's environments and tenants.
- For a worker, WorkerEdit.
- The machine or endpoint behind the target or worker still exists and hasn't changed. For Tentacles, the Tentacle must still be installed with the same certificate, so its thumbprint matches the one in the audit event.
- Everything the target or worker referenced still exists, such as environments, tenants, worker pools, machine policies, accounts, and certificates. If any of these were also deleted, re-create them first.
- If the deletion happened before your audit log retention period, access to the archived audit log files. Self-hosted customers need access to the server folder configured under Configuration ➜ Settings ➜ Server Folders.
Steps
-
Find the deletion event in the audit log. In the Octopus Web Portal, go to Configuration ➜ Audit. Use the advanced filters to narrow the results:
-
Set Event categories to Document Deleted.
- Set Document types to Machine for a deployment target, or Worker for a worker.
-
Set the date range to when you think the deletion happened.
Look for an event naming the deleted target or worker. The event also shows who deleted it, or whether the system removed it as part of a machine policy cleanup. -
Check the archived audit logs if the event isn't listed. From Octopus 2023.3, events older than the event retention period (set in Configuration ➜ Settings ➜ Event Retention) are archived out of the database into files. Open the archived file for the day of the deletion and search it for the target or worker name. On self-hosted Octopus Server, the files are in the archived events folder set under Configuration ➜ Settings ➜ Server Folders.
-
Inspect the deleted settings. Click expansion arrow on the deletion event to see the target or worker as it was before it was deleted. Copy the details into a text file and keep it open, so you can refer to it while you add the record again. As an example, this entry might look like the following:
{
"Roles": [
"my-role"
],
"IsDynamic": false,
"IsCreatedByScript": false,
"EnvironmentIds": [
"Environments-1"
],
"TenantedDeploymentParticipation": "Untenanted",
"TenantIds": [],
"TenantTags": [],
"ProjectIds": [],
"OwnerEntityName": "DeploymentTarget",
"SpaceId": "Spaces-1",
"Id": "Machines-1",
"Name": "Test",
"Endpoint": {
"DeploymentTargetType": "TentaclePassive",
"ProxyId": null,
"Thumbprint": "EXAMPLE",
"Uri": "https://example.octopus.com:10933/",
"UpgradeLocked": false
},
"Slug": "test",
"IsDisabled": false,
"MachinePolicyId": "MachinePolicies-1",
"OperatingSystem": "Unknown",
"ShellName": "Unknown",
"ShellVersion": "Unknown",
"Architecture": "Unknown",
"OperatingSystemVersion": "Unknown",
"IsRunningInContainer": null
}
-
Note the settings you need. From the event details, note these values.
For both deployment targets and workers: -
Name MachinePolicyIdIsDisabled-
Endpoint, which describes how Octopus connects. Note theCommunicationStyle(for example,TentaclePassivefor a Listening Tentacle,TentacleActivefor a Polling Tentacle, orSshfor SSH), plus theUriandThumbprintfor Tentacles, or the host, port, and account for SSH
For a deployment target only: EnvironmentIds-
Roles(target tags) -
TenantedDeploymentParticipation,TenantIds, andTenantTags
For a worker only: -
WorkerPoolIds -
Match the IDs to names. The event details record environments, tenants, worker pools, machine policies, and accounts by ID, but the Web Portal shows them by name. To find the name for an ID, open the matching page in the Web Portal and look for the ID in the address bar. For example, an environment's page URL ends with its ID, such as
Environments-42. Write the name next to each ID in your notes. -
Add the target or worker in the Web Portal.
-
For a deployment target, go to Infrastructure ➜ Deployment Targets ➜ Add Deployment Target.
- For a worker, go to Infrastructure ➜ Workers ➜ Add Worker.
Choose the same target type and communication style you noted in step 4, then enter the settings from your notes: - Use the same name.
- For a deployment target, select the same environments, target tags, and tenant settings.
- For a worker, select the same worker pools.
-
Under advanced settings, select the same machine policy.
For a Listening Tentacle, enter the hostname and port from theUri. Octopus contacts the Tentacle and shows its thumbprint. Check this matches theThumbprintin the event details before you save.
Polling Tentacles and Kubernetes agents register from the machine side, so the Web Portal shows a command or installation steps instead of a form. Run those on the original machine, using the same environments and target tags, or the same worker pools, from your notes. -
Re-enter any sensitive values. The audit log doesn't record sensitive values, such as a password on an SSH endpoint. If the target or worker used one, enter it again in its connection settings.
-
Update anything that referenced the old ID. Search scripts, Config as Code projects, and infrastructure as code (such as Terraform) for the old machine or worker ID, and replace it with the new one. Deployment process steps scoped by target tag or by worker pool don't need changes.
Verify
- Open the re-created record under Infrastructure ➜ Deployment Targets or Infrastructure ➜ Workers.
- Compare its settings with the event details you saved:
- For a deployment target, check the name, environments, target tags, tenants, and machine policy.
- For a worker, check the name, worker pools, and machine policy.
- On the Connectivity tab, click Check health. The health check should complete with a Healthy status. If it fails with a thumbprint error, the Tentacle certificate has changed since the deletion, so update the thumbprint to match the Tentacle's current one.
- Confirm the record does its job:
- For a deployment target, deploy a release to the target's environment and confirm the deployment runs on the target.
- For a worker, run a deployment or runbook with a step that uses the worker's pool, and confirm the task log shows the step running on the worker.
- In Configuration ➜ Audit, check there's a new Document Created event for the target or worker.
Related
- Auditing explains what Octopus records in the audit log, event retention, and archived audit logs.
- Deployment targets covers each target type and how to add it.
- Workers explains how workers and worker pools work, and how to add a worker.
- Machine policies explains how cleanup settings can delete unavailable targets and workers automatically, which helps prevent this from happening again.
- Register a Listening Tentacle with the API has scripts for adding targets with the REST API, if you need to re-create many at once.
- Backup and restore describes restoring the Octopus database, an alternative if you need to recover many records along with their history.