# Uninstall and migrate

Uninstall nodes and the controller, keep or purge data, and migrate the controller to a new machine from a backup.


## Uninstall a node
On the node server, as root:

```
gocdn-node-uninstall
```

This stops and removes the node's services, program and firewall rules, but keeps its identity, config, cache and logs; re-running the install command restores the same node without a new token. Add `--purge` to remove everything; to reconnect afterwards you need a new token and must delete the old node in the panel. The last line is `NODE_UNINSTALL_DONE`; any leftovers are listed one by one.

## Uninstall the controller
On the controller server, as root, run `gocdn-master-uninstall`. It stops and removes the controller services but keeps the database, keys and config; re-running the install command restores it. With `--purge` the business database, ClickHouse database, keys and config are deleted too.

:::warn
`--purge` cannot be undone. Make sure a backup is on another machine first, especially off-box copies of the signing key and the credential encryption key.
:::

## Migrate the controller to a new machine
By default the controller backs up the business database hourly and key ClickHouse tables daily; for settings and encryption see [Backup and point-in-time restore](https://www.gocdn888.com/en/guide/backup). To migrate: install the same version of the controller on the new machine, stop the service, restore the database from a backup, and start again.

1. On the old controller, pick the latest backup, copy it to the new machine, and also copy the signing key and credential encryption key.
2. Install the controller on the new machine with the install command, using the same version as the old one.
3. Stop the controller service and run `gocdn-master db-restore < gocdn-db-<time>.sql.gz`. The last line is `DB_RESTORE_DONE`.
4. Start the service, check the data, and update the node communication address under System Admin › Upgrade & Maintenance › Node Communication to the new controller.

:::tip
With an offsite copy directory configured, `-until` can restore to any point in time; see [Backup and point-in-time restore](https://www.gocdn888.com/en/guide/backup) for the steps.
:::