# Recreate a server from a file

A common way to save money: when you finish for the day, destroy the server instead of keeping it, and launch the same setup again tomorrow. A launch file makes that one command. This tutorial takes about ten minutes and needs the CLI (see [Use the CLI and API from scratch](/docs/tutorial-cli-and-api)).

Destroying a server deletes its disk. Copy anything you want to keep first, or keep it on a volume (see [Fine-tune or train: keep your work safe](/docs/tutorial-keep-your-work-safe)).

## 1. Find the server

```bash
apidly servers
```

Note the id of the server you want to keep, for example `ins_example`.

## 2. Save its launch file

```bash
apidly servers export ins_example -f my-server.json
```

You see `Wrote my-server.json`. Read the lines after it:

- `Not in the file (send them when you launch, e.g. --env NAME=VALUE): HF_TOKEN` names the secrets you send again in step 5.
- `Not carried by a launch file: ...` names what the file cannot hold, such as an attached volume.

In the console the same file comes from the server's **Settings** tab, **Download launch file**.

## 3. Look inside

Open `my-server.json` in any editor. It holds the plan, template, disk size, SSH keys, plain variables, pricing, tags and repeating automation rules, and no secret values. You can change it now, for example a larger `diskGb` or a new `label`. See [Launch file](/docs/launch-file) for every field.

## 4. Destroy the server

```bash
apidly destroy ins_example
```

Type the server id when asked. Compute and disk charges stop. The launch file costs nothing to keep.

## 5. Launch it again

When you need the server again, first check the price, then launch:

```bash
apidly deploy -f my-server.json --env HF_TOKEN=hf_example --dry-run
apidly deploy -f my-server.json --env HF_TOKEN=hf_example --wait
```

The first command shows the hourly price and anything that would refuse the launch, such as a low balance, and creates nothing. The second asks `Deploy? [y/N]`, then waits until the server runs. It gets a new id, new ports and a fresh disk from the template.

To avoid typing a secret each time, store it once in **Secrets** and change its value in the file to `secret:HF_TOKEN` (see [Secrets](/docs/secrets)). The file then stays free of secret values and needs no `--env`.

## If something goes wrong

- `my-server.json is not a launch file: it needs planId and templateId`: the file was cut short or is not the exported one. Export it again.
- The plan is out of stock: launch with another plan, for example `--plan PLAN_SLUG` (see `apidly plans`), or add plans to `fallbackPlanIds` in the file.
- The server starts but the app complains about a missing token: a name from step 2 was not sent. Destroy it and launch again with `--env`.

## Next

- [Launch file](/docs/launch-file)
- [Control costs: stop, auto-stop, budgets and auto top-up](/docs/tutorial-save-money)
- [Check the price before you launch](/docs/tutorial-check-the-price)
