2022-02-21 08:16:54 +01:00
---
title: Backup
sidebar_position: 10
---
## Create a backup
This guide walk you though the steps required to create a full backup of your installation.
:::info
Remember to **automate** and **test** the backup process and to have it run regularly. Having an **automated** and **tested** restoring process is also recommended.
:::
:::caution
2022-09-24 17:40:05 +02:00
Feel free to pick the backup software of your choice, but know that rsync and similar tools aren't backup tools. You could use [restic ](https://restic.net/ ) or [borg ](https://borgbackup.readthedocs.io/ ).
2022-02-21 08:16:54 +01:00
:::
### Backup the configuration
2022-06-06 17:10:44 +02:00
On common setups, you need to backup the entire `/etc/libretime` folder.
2022-02-21 08:16:54 +01:00
### Backup the database
You need to backup the PostgreSQL database, which holds the entire data of your installation.
2023-03-20 11:54:22 +01:00
Here is an example to dump your PostgreSQL database to a plain text SQL file:
2022-02-21 08:16:54 +01:00
```bash
2023-03-20 11:54:22 +01:00
sudo -u postgres pg_dump --no-owner --no-privileges libretime > libretime.sql
2022-02-21 08:16:54 +01:00
```
2022-08-25 09:50:31 +02:00
:::note
2023-03-20 11:54:22 +01:00
We use the `--no-owner` and `--no-privileges` flags to ignore roles
2022-08-25 09:50:31 +02:00
and permissions details about the database. This can be useful when restoring
2023-03-20 11:54:22 +01:00
to database or role that have different names (e.g. `airtime` to `libretime` ).
2022-08-25 09:50:31 +02:00
:::
2022-02-21 08:16:54 +01:00
Please read the `pg_dump` usage for additional details.
### Backup the storage
You need to backup the entire file storage, which holds all the files of your installation.
2023-04-21 11:46:30 +02:00
The path to your storage is defined in the [configuration ](./configuration.md ) file.
2022-02-21 08:16:54 +01:00
## Restore a backup
2022-08-25 09:50:31 +02:00
### Install or cleanup
2023-04-21 11:50:37 +02:00
If you are restoring a backup on a fresh system, we recommend that you first [install LibreTime ](./install/README.md ), and **stop before the [setup tasks](./install/README.md#setup)** .
2022-08-25 09:50:31 +02:00
If you are restoring a backup on an existing system, make sure to clean the old **database** and **files storage** .
2022-02-21 08:16:54 +01:00
### Restore the configuration
2023-04-21 11:46:30 +02:00
Copy the backed configuration files back to the [configuration ](./configuration.md ) folder.
2022-08-25 09:50:31 +02:00
2023-04-21 11:46:30 +02:00
If you are upgrading LibreTime, edit the configuration file to match the new configuration schema and update any changed values. See the [configuration ](./configuration.md ) documentation for more details.
2022-02-21 08:16:54 +01:00
### Restore the database
2023-03-20 11:54:22 +01:00
Restore the database by using the one of the following command depending on the format of you backup file:
2022-08-25 09:50:31 +02:00
```bash
2023-03-20 11:54:22 +01:00
# With a plain text SQL file
sudo -u libretime libretime-api dbshell < libretime.sql
# With a custom pg_dump format
sudo -u postgres pg_restore --no-owner --no-privileges --dbname=libretime libretime.dump
2022-08-25 09:50:31 +02:00
```
2023-03-20 11:54:22 +01:00
:::info
The `libretime-api dbshell` command is a shortcut to the `psql` command, and automatically passes the database access details (e.g. database name, user, password).
:::
2022-08-25 09:50:31 +02:00
:::note
2023-03-20 11:54:22 +01:00
We use the `--no-owner` and `--no-privileges` flags to ignore roles
2022-08-25 09:50:31 +02:00
and permissions details about the database. This can be useful when restoring
to database or role that have different names.
:::
2023-04-21 11:50:37 +02:00
If you are upgrading LibreTime, make sure to apply the [database migration ](./install/upgrade.md#apply-migrations ).
2022-02-21 08:16:54 +01:00
### Restore the storage
2022-08-25 09:50:31 +02:00
Copy the entire backed file storage back to the storage path.
2023-04-21 11:46:30 +02:00
The path to your storage is defined in the [configuration ](./configuration.md ) file.