import { TabsGroup, TabsItem } from "@/components/DocsTabs";
import Alert from "@/components/DocsAlert";
import SupportOptions from "@/components/SupportOptions";

# Backup and Restore

Firezone can be safely backed up and restored in a couple of minutes under most
circumstances.

<Alert
  color="info"
  html={`
This guide is written for Firezone deployments using <strong>Docker Engine</strong>
on <strong>Linux</strong> only.
`}
/>

Unless your hosting provider supports taking live VM snapshots, you'll need to
stop Firezone before backing it up. This ensures the Postgres data directory is
in a consistent state when the backup is performed. Backing up a running
Firezone instance will **most likely** result in data loss when restored; you
have been warned.

After stopping Firezone, backing up Firezone is mostly a matter of copying the
relevant [files and directories](/docs/reference/file-and-directory-locations)
to a location of your choosing.

See the steps below for specific examples for Docker and Omnibus.

<TabsGroup>
<TabsItem title="Docker" active>

### Backup

For Docker-based deployments, this will consist of backing up the
`$HOME/.firezone` directory along with the Postgres data directory, typically
located at `/var/lib/docker/volumes/firezone_postgres-data` on Linux if you're
using the default Docker compose template.

1. Stop Firezone (warning: this **will** disconnect any users connected to the
   VPN):

```
docker compose -f $HOME/.firezone/docker-compose.yml down
```

2. Copy relevant files and folders. If your made any customizations to
   `/etc/docker/daemon.json` (for example, for IPv6 support), be sure to include
   that in the backup as well.

```
tar -zcvfp $HOME/firezone-back-$(date +'%F-%H-%M').tgz $HOME/.firezone /var/lib/docker/volumes/firezone_postgres-data
```

A backup file named `firezone-back-TIMESTAMP.tgz` will then be stored in
`$HOME/`.

### Restore

1. Copy the files back to their original location:

```
tar -zxvfp /path/to/firezone-back.tgz -C / --numeric-owner
```

2. Optionally, enable Docker to boot on startup:

```
systemctl enable docker
```

</TabsItem>
<TabsItem title="Omnibus">

### Backup

1. Stop Firezone (warning: this **will** disconnect any users connected to the
   VPN):

```
firezone-ctl stop
```

2. Copy relevant files and folders:

```
tar -zcvfp $HOME/firezone-back-$(date +'%F-%H-%M').tgz /var/opt/firezone /opt/firezone /usr/bin/firezone-ctl /etc/systemd/system/firezone-runsvdir-start.service /etc/firezone
```

A backup file named `firezone-back-TIMESTAMP.tgz` will then be stored in
`$HOME/`.

### Restore

1. Copy the files back to their original location:

```
tar -zxvfp /path/to/firezone-back.tgz -C / --numeric-owner
```

2. Reconfigure Firezone to ensure configuration is applied to the host system:

```
firezone-ctl reconfigure
```

</TabsItem>
</TabsGroup>

<SupportOptions />
