doc/pages/02.administer/15.admin_guide/50.backups/backup.md

190 lines
7.2 KiB
Markdown
Raw Normal View History

2020-11-11 11:47:10 +01:00
---
2021-09-02 17:59:06 +02:00
title: Backing up your server
2020-11-11 11:47:10 +01:00
template: docs
taxonomy:
category: docs
routes:
default: '/backup'
2020-11-11 11:47:10 +01:00
---
2016-01-20 16:52:42 +01:00
2021-09-02 17:59:06 +02:00
In the context of self-hosting, backups are an important element to compensate for unexpected events (fire, database corruption, loss of access to the server, compromised server...). The backup policy to implement depends on the importance of the services and data you manage. For example, backing up a test server will be of little interest, while you will want to be very careful if you are managing critical data for an association or a company - and in such cases, you will want to store the backups *in a different location or locations*.
2021-09-02 17:59:06 +02:00
## Manual backup
### Backup
2021-12-29 13:42:46 +01:00
YunoHost comes with a backup system, that allows you to backup (and restore) system configurations and data (e.g. emails) and apps if they support it.
2021-12-29 13:42:46 +01:00
You can manage backups either from the command line (`yunohost backup --help`) or from the web administration (in the Backups section), though some features are not yet available in the webadmin.
2021-09-02 17:59:06 +02:00
The current default method consists in creating a `.tar` archive containing all relevant files.
2021-09-02 17:59:06 +02:00
#### Creating backups
2021-09-02 17:59:06 +02:00
[ui-tabs position="top-left" active="0" theme="lite"]
[ui-tab title="From the webadmin"]
2021-12-29 13:42:46 +01:00
You can easily create backup archives from the webadmin by going to `Backups > Local storage` and clicking on `New backup`. You will then be asked to select which configuration, data and apps you want to backup.
2021-02-06 19:02:44 +01:00
![picture of YunoHost's backup pannel](image://backup.png)
2021-09-02 17:59:06 +02:00
[/ui-tab]
[ui-tab title="From the command line"]
2021-12-29 13:42:46 +01:00
You can create a new backup archive from the command line. Here are a few simple examples of commands and their corresponding behavior:
2020-09-14 11:50:33 +02:00
- Backing up everything (all system parts and apps):
```bash
yunohost backup create
```
- Backing up only apps
```bash
yunohost backup create --apps
```
- Backing up only two apps (wordpress and shaarli)
```bash
yunohost backup create --apps wordpress shaarli
```
2021-12-29 13:42:46 +01:00
- Backing up only emails
```bash
yunohost backup create --system data_mail
```
2016-01-20 16:52:42 +01:00
2021-12-29 13:42:46 +01:00
- Backing up emails and wordpress
```bash
yunohost backup create --system data_mail --apps wordpress
```
2016-01-26 16:27:05 +01:00
2021-12-29 13:42:46 +01:00
For more information and options about backup creation, consult `yunohost backup create --help`. You can also list the system parts that can be backed up with `yunohost hook list backup`.
2021-09-02 17:59:06 +02:00
[/ui-tab]
[/ui-tabs]
2016-01-26 16:27:05 +01:00
2021-09-02 17:59:06 +02:00
#### Downloading backups
2016-01-26 16:27:05 +01:00
2021-09-02 17:59:06 +02:00
[ui-tabs position="top-left" active="0" theme="lite"]
[ui-tab title="From the webadmin"]
2021-12-29 13:42:46 +01:00
After creating backups, it is possible to list and inspect them using the corresponding views in the web administration interface. A button allows you to download the archive. If the archive is larger than 3GB, it may be better to proceed via SFTP.
2016-01-26 16:38:11 +01:00
2021-09-02 17:59:06 +02:00
`Backup > Local Archives > <Archive name> > Download`
2016-01-26 16:27:05 +01:00
2021-09-02 17:59:06 +02:00
[/ui-tab]
[ui-tab title="With a SFTP client"]
Currently, the most accessible way to download big archives is to use the program FileZilla as explained in [this page](/filezilla).
2016-01-26 16:27:05 +01:00
2021-09-02 17:59:06 +02:00
By default, backups are stored in `/home/yunohost.backup/archives/`.
2016-01-26 16:27:05 +01:00
2021-09-02 17:59:06 +02:00
[/ui-tab]
[ui-tab title="From the command line"]
The `yunohost backup list` and `yunohost backup info <archive_name>` commands provide information about the names and sizes of backups.
2016-01-26 16:27:05 +01:00
2021-09-02 17:59:06 +02:00
It is possible to use `scp` (a program based on [`ssh`](/ssh)) to copy files between two machines via the command line. So, from a GNU/Linux machine, you can use the following command to download an archive:
2016-01-26 16:38:11 +01:00
2016-01-26 16:27:05 +01:00
```bash
2021-09-02 17:59:06 +02:00
scp admin@your.domain.tld:/home/yunohost.backup/archives/<archive_name>.tar ./
2016-01-26 16:27:05 +01:00
```
If your SSH port is different from 22
```bash
scp -P ssh_port admin@your.domain.tld:/home/yunohost.backup/archives/<archive_name>.tar ./
```
2021-09-02 17:59:06 +02:00
[/ui-tab]
[/ui-tabs]
2016-01-26 16:27:05 +01:00
2021-12-29 13:42:46 +01:00
! Don't forget to store your backup in a different place to your server.
2016-01-26 16:27:05 +01:00
2021-12-29 13:42:46 +01:00
!!! If you want, you can connect an external disk to your server so that the archives arrive directly on it. See this guide to [Adding external storage to your server](/external_storage)
2016-01-26 16:27:05 +01:00
2021-09-02 17:59:06 +02:00
### Testing
2021-12-29 13:42:46 +01:00
You should regularly test your backups by at least listing the contents of the archives and checking the size of the associated data. It is best to practice restoring regularly.
2021-09-02 17:59:06 +02:00
```bash
# List the files
tar -tvf /home/yunohost.backup/archives/ARCHIVE.tar | less
2021-09-02 17:59:06 +02:00
# List database exports
tar -tvf /home/yunohost.backup/archives/ARCHIVE.tar | grep "(db|dump)`.sql"
2016-01-26 16:27:05 +01:00
2021-09-02 17:59:06 +02:00
# Check the weight
ls -lh /home/yunohost.backup/archives/ARCHIVE.tar
2016-01-26 16:27:05 +01:00
```
2021-09-02 17:59:06 +02:00
### Restoring backups
!!! SPOILER: The larger your data volume and the more applications you have, the more complex your recovery will be.
2021-09-02 17:59:06 +02:00
#### Simple case: little data, archive already present
[ui-tabs position="top-left" active="0" theme="lite"]
[ui-tab title="From the webadmin"]
2021-09-02 17:59:06 +02:00
Go in `Backup > Local storage` and select your archive. You can then select which items you want to restore, then click on 'Restore'.
2021-09-02 17:59:06 +02:00
![picture of YunoHost's restore pannel](image://restore.png)
2016-01-26 16:27:05 +01:00
2021-09-02 17:59:06 +02:00
[/ui-tab]
[ui-tab title="From the command line"]
From the command line, you can run `yunohost backup list` to get the available archive names. They are basically their file name without extension.
2021-12-29 13:42:46 +01:00
You can then run `yunohost backup restore <archivename>` (hence without its `.tar` extension) to restore an archive. As for `yunohost backup create`, this will restore everything in the archive by default. If you want to restore only specific items, you can use something like `yunohost backup restore <archivename> --apps wordpress`, which will restore only the wordpress app.
2016-01-26 16:27:05 +01:00
2021-09-02 17:59:06 +02:00
!!! In the case of a complete restoration, it is possible to restore instead of launching the initial configuration.
[/ui-tab]
[/ui-tabs]
2021-09-02 17:59:06 +02:00
To restore an app, the domain on which it was installed should already be configured (or you need to restore the corresponding system configuration). You also cannot restore an app which is already installed... which means that to restore an old version of an app, you must first uninstall it.
2016-01-26 16:27:05 +01:00
2021-09-02 17:59:06 +02:00
#### Upload an archive
2016-01-26 16:27:05 +01:00
2021-12-29 13:42:46 +01:00
In many cases, the archive is not on the server on which you want to restore it. So it has to be uploaded, which depending on its size can take more or less time.
2021-09-02 17:59:06 +02:00
[ui-tabs position="top-left" active="0" theme="lite"]
[ui-tab title="With an SFTP client"]
Currently, the most accessible solution for uploading backups is to use the FileZilla program as explained in [this page](/filezilla).
2021-09-02 17:59:06 +02:00
By default, backups are to be placed in `/home/yunohost.backup/archives/`.
[/ui-tab]
[ui-tab title="From the command line"]
You can upload a backup from a machine to your server with :
```bash
scp /path/to/your/<archive_name>.tar admin@your.domain.tld:/home/yunohost.backup/archives/
```
If your SSH port is different from 22
```bash
scp -P ssh_port /path/to/your/<archive_name>.tar admin@your.domain.tld:/home/yunohost.backup/archives/
```
2021-09-02 17:59:06 +02:00
[/ui-tab]
[/ui-tabs]
2021-09-02 17:59:06 +02:00
## Automatic or remote backup
2021-09-02 17:59:06 +02:00
There are 3 YunoHost applications that offer to extend YunoHost with an automated backup method.
2021-09-02 17:59:06 +02:00
* [BorgBackup](/backup/borgbackup)
* [Restic](/backup/restic)
* [Archivist](/backup/archivist)
2021-09-02 17:59:06 +02:00
## Go further
2021-09-02 17:59:06 +02:00
* [Evaluate the quality of your backup](/backup/strategies)
* [Clone your file system](/backup/clone_filesystem)
* [Avoid a hardware failure](/backup/avoid_hardware_failure)
* [Include/exclude files](/backup/include_exclude_files)
* [Custom methods](/backup/custom_backup_methods)
* [Migrate or merge servers](/backup/migrate_or_merge_servers)
2020-01-15 22:09:43 +01:00