# Restore to a new server

> When a server is lost, put the agent on a new machine in its place and restore the old server's backups there.

A restore always goes back to the server the backup came from: you cannot pick another server as the target. When a machine is lost, this is the disaster recovery path. You install the agent on a new machine as the same server in Clokeep, then restore its backups there. It works for **Files**, **Email** and **Database** plans, and for **Plesk server** and **cPanel server** plans. Plesk and cPanel servers have their own steps under [Plesk and cPanel servers](/docs/restores/new-server#plesk-and-cpanel-servers).

## Prerequisites

- The Admin or Operator role.
- The server still in the panel. If you deleted it, its backups can be downloaded but no longer restored. See [Browse a backup](/docs/restores/browse#orphaned-backups).
- A new machine that meets the agent's [prerequisites](/docs/servers/install-agent#prerequisites), with access to your storage.
- For a database backup, the `mysql` or `psql` client and a database server on the new machine. The database and user that the connection names must exist there, with the password stored in the connection. Otherwise edit the connection on the server's **Database Connections** tab.

## Move the server to the new machine

<Warning>
Switch off **Active** before the new machine checks in. Otherwise its scheduled backups run on the new, empty machine. A backup that finds some of its folders missing skips them and can still end **Completed**. Retention then counts it as one of the newest backups and can delete your good ones. An incremental backup also records the missing files as deleted. A Files backup that finds all of its folders missing fails instead, from agent 3.2.0.

Retention keeps deleting while the server is paused. It never deletes a plan's newest successful backup, but older ones can expire. If the plan uses **Keep backups for** and you may need an older backup, raise that number before you start.
</Warning>

<Steps>
<Step title="Pause the server">
Open the server's page, switch off **Active** and click **Save changes**. Scheduled backups pause and **Run now** is refused. Restores still run. In **Backup Runs**, stop any backup of this server that is still **Queued**, or the new machine picks it up. See [Run and stop a backup](/docs/backups/run-stop#stop-a-run).
</Step>
<Step title="Shut out the old machine">
Click **More actions** > **Revoke agent tokens** and confirm. An agent that still runs on the old machine can no longer reach the panel. Enrolling the new machine in the next step also revokes the old machine's tokens, but revoking now shuts it out before then.
</Step>
<Step title="Install the agent on the new machine">
Click **Generate install command** at the top of the server's page. Run the command as root on the new machine, as in [Install the agent](/docs/servers/install-agent). The agent enrolls as this server. **Agent status** turns **Online**, and the page shows the new machine's IP address.
</Step>
<Step title="Prepare the new machine">
On a server without Plesk or cPanel, the agent restores files only into `/var/lib/clokeep-restore` at first. To restore into the original folders, add them to the agent's [allowed folders](/docs/restores/files-databases#allowed-folders). If you picked a **Work directory** for the old machine, check it: a folder or disk the new machine does not have makes every run fail. Pick one the new machine offers, or leave the field empty.
</Step>
<Step title="Restore each backup">
For each plan, open **Browse Backups**, pick the server, the plan and its newest run, and click **Restore selected backup**. An incremental backup brings back its whole chain, so one restore per plan is enough. See [Restore files, email and databases](/docs/restores/files-databases). A server runs one restore at a time, so wait for each to end before the next.
</Step>
<Step title="Switch the server back on">
When your data is back, switch **Active** on again and click **Save changes**. On an incremental plan, start with **More actions** > **Run full backup now** on the plan's page. The next incremental backup would otherwise record every file you did not restore as deleted.
</Step>
</Steps>

Your plans, backup paths, database connections, schedules, storages and backups stay with the server in the panel. You do not set them up again.

## Plesk and cPanel servers

A new machine with the same control panel can get every subscription or account back from its backups. Clokeep creates each one again from its saved settings, then restores its files, databases and mail into it. One [restore batch](/docs/restores/bulk-restore) does it for the whole server.

### Before you start

- A new machine with the same control panel freshly installed: Plesk for a Plesk server, cPanel for a cPanel server. Leave it empty. A subscription or account that already exists there is not created again.
- A Plesk licence with room for every subscription. A subscription beyond the licence's limit fails with Plesk's message.
- Backups that include **Settings**. New plans include it. Without it, a subscription or account cannot be created again. See [Plesk servers](/docs/servers/plesk) and [cPanel servers](/docs/servers/cpanel).
- On Plesk, agent 3.1.1 or later. Earlier agents fail with "The signature of the backup header is not valid", because Plesk signs each backup with a key of the machine that made it. The install command always installs the current agent.

### Steps

<Steps>
<Step title="Move the server to the new machine">
Follow the first three steps under [Move the server to the new machine](/docs/restores/new-server#move-the-server-to-the-new-machine): pause the server, revoke its agent tokens, and install the agent on the new machine. Once the agent checks in, it reports that the new machine has none of the old subscriptions or accounts. They stay in Clokeep with their backups, marked as no longer on the server.
</Step>
<Step title="Start one restore batch">
On the server's page, click **Restore accounts** and keep **The newest backup of each account**. Leave every account ticked, except any you deleted on purpose before the machine was lost. Under **Restore**, tick **Settings**, **Files**, **Databases** and **Mail**, and switch on **Apply the settings to the server**. Type the server's name and click **Restore accounts**. See [Restore many accounts at once](/docs/restores/bulk-restore).
</Step>
<Step title="Follow the batch">
Accounts are created again one after another, each in a minute or two. An account that fails does not stop the others. Fix the reason, then click **Retry failed accounts**.
</Step>
<Step title="Check each subscription or account">
From the batch's page, open each account's restore run and read its log for warnings. A restore that ends with a warning can still count as **Restored** in the batch. Then check the sites in Plesk or WHM. What to look for is under [What comes back](/docs/restores/new-server#what-comes-back).
</Step>
<Step title="Switch the server back on">
Switch **Active** on again and click **Save changes**. The subscriptions or accounts show as on the server again after the next sync.
</Step>
</Steps>

### What comes back

Each subscription or account comes back with its domains, files, databases, mailboxes and mail, and its original passwords. On Plesk, also its DNS records and database users. Some things are not in any backup, so set them up on the new machine yourself: the control panel's own configuration, PHP versions and extensions, and licences.

On Plesk:

- A subscription whose customer the new Plesk does not have comes back under the Plesk administrator. The restore run's log names the original customer. Create the customer in Plesk and move the subscription to it.
- A subscription comes back without its service plan. Attach it to a plan in Plesk again if you use plans.

On cPanel:

- An account keeps its user name and domain. cPanel gives it a new user ID, and its files are owned by the new one.

Clokeep has tested this with a new machine on the old machine's IP address. With another IP address, check each site's IP in Plesk or WHM after the restore.

## Without the agent

You can also download a whole backup in **Browse Backups** and unpack it yourself. Its format is the plan's compression profile, by default a `.tar.zst` archive. A download of an incremental backup holds only the files that changed in that run, while a file or folder downloaded from **Contents** comes from the complete tree. See [Download and share](/docs/restores/download-share).

## Next steps

<CardGroup cols="2">
<Card title="Restore files, email and databases" href="/docs/restores/files-databases" icon="play">
What each restore choice overwrites.
</Card>
<Card title="Install the agent" href="/docs/servers/install-agent" icon="term">
Put the agent on the new machine.
</Card>
</CardGroup>
