# Move data in and out

A server's disk goes away when you destroy the server. This tutorial shows how to get data onto a server, and how to get your results off it. You need a running server with an SSH key; see [Connect with SSH](/docs/connect-ssh). Open the server's **Connect** tab and note the **Host**, the **Port** and the user, `root`. In the commands below, replace `HOST` and `PORT` with them.

## 1. Check the disk first

Connect with SSH and look at the free space before a large copy:

```bash
df -h /workspace
```

The `Avail` column shows what is left. The disk size is set when you deploy, so a dataset larger than the disk will not fit.

## 2. Copy a file with scp

From your own computer:

```bash
scp -P PORT ./notes.txt root@HOST:/workspace/
scp -P PORT root@HOST:/workspace/results.tar.gz ./
```

The first line uploads, the second downloads. `scp` takes a capital `-P` for the port. Add `-r` to copy a folder. If your key is not in the default place, add `-i ~/.ssh/your_key`.

If you installed the command-line tool, the same copy needs no host and port. A path that starts with `:` is on the server:

```bash
apidly scp ins_ID ./notes.txt :/workspace/
apidly scp ins_ID :/workspace/out ./out -r
```

## 3. Sync a folder with rsync

For a dataset or checkpoints, use `rsync`. If the connection breaks, run the same command again and it continues where it stopped:

```bash
rsync -avz -e "ssh -p PORT" ./data/ root@HOST:/workspace/data/
rsync -avz -e "ssh -p PORT" root@HOST:/workspace/checkpoints/ ./checkpoints/
```

The trailing `/` on `./data/` matters: it copies the contents of the folder. Many small files are faster as one archive: `tar -czf data.tar.gz ./data`.

## 4. Check that it arrived

Compare a checksum on both sides. The two lines must match:

```bash
sha256sum /workspace/results.tar.gz
sha256sum ./results.tar.gz
```

On macOS use `shasum -a 256` for your own computer. Run the first line on the server and the second on your computer.

## 5. Copy between two of your servers

Both servers must be running.

1. Open **Storage** and select the **Transfers** tab.
2. Select **Copy between servers**.
3. Choose **From server** and the **Folder on that server**, then **To server** and its folder.
4. Select **Start copy**.

Files with the same name at the destination are overwritten. Each server runs one transfer at a time. See [Volumes and copies](/docs/storage).

## 6. Back up to your own bucket

A helper script copies a folder to any S3-compatible storage that you own. On the server:

```bash
curl -fsSLO https://apidly.com/downloads/gpu-backup.sh
curl -fsSL https://apidly.com/downloads/SHA256SUMS | grep ' gpu-backup\.sh$' | sha256sum -c - && chmod +x gpu-backup.sh
./gpu-backup.sh setup
./gpu-backup.sh backup /workspace my-project
```

The check prints `gpu-backup.sh: OK`. `setup` asks for your bucket's endpoint, region, bucket name, key and secret, and saves them only on the server. To see what it would copy first, add `--dry-run` to any command. On a new server, download the helper, run `setup` again and restore:

```bash
./gpu-backup.sh list
./gpu-backup.sh restore my-project /workspace
```

Your storage provider charges for the stored data and for downloads, under your own agreement. Use a key that can reach only this bucket. See [Back up to your own storage](/docs/backups).

## Which method when

| Need | Use |
|---|---|
| One file | `scp` |
| A big folder, or a flaky connection | `rsync` |
| Server to server | **Copy between servers** |
| A copy that outlives the server | Your own bucket |

More detail is in [Moving data](/docs/data-movement).

## When you are done: stop or delete

Copy first, then clean up. **Stop** keeps the disk and its files but still charges for the disk. **Destroy** ends every charge and deletes the disk, so run a backup or download before you do it. See [Start, stop and restart](/docs/start-stop-restart).

## Next

- [Common mistakes and how to fix them](/docs/tutorial-common-mistakes)
- [Save money](/docs/tutorial-save-money)
