1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
Back up a Web hosting with Restic on Swiss Backup (Swift)
This guide details how to back up data from your Web hosting (Starter, shared or Serveur Cloud) using the application restic via the OpenStack Swift protocol on Swiss Backup, an independent Swiss cloud backup solution.
Other solutions exist to back up your web data: check out this other guide.
Prerequisites
- Use a Web Hosting.
- Have a Swiss Backup Infomaniak space with at least one available device quota for a Cloud backup.
- Add 1 device of type Cloud to obtain the OpenStack Swift parameters.
⚠️ All the services offered by Infomaniak are compatible with the corresponding standard protocols (notably IMAP/SMTP for email, WebDAV for sharing, S3/Swift for storage, etc.). Therefore, if you encounter a problem with third-party software, contact its publisher directly or a Partner and consult the support policy as well as article 11.9 of the Infomaniak Terms and Conditions.
Install Restic
For this:
Download the linux_amd64 binary from the restic github repository:
uid@h2web:~$ wget -O restic.bz2 https://github.com/restic/restic/releases/download/v0.14.0/restic_0.14.0_linux_amd64.bz2
⚠️ The download link may change with the release of a new version; version 0.14 uses default compression.
Unzip the archive and make the binary executable:
uid@h2web:~$ bunzip2 restic.bz2 uid@h2web:~$ chmod +x restic
Set up Restic
Creation of an encryption key to encrypt the data
- The key cannot be changed and if lost, the data will no longer be readable.
- Place this key in a file readable by Restic.
Example of key generation:
uid@h2web:~$ openssl rand -base64 16 > restickey
Configuration of restic
To configure the backup:
Create a file resticconfig with the following content to be adapted according to the information specific to your device:
echo "export OS_AUTH_URL=https://swiss-backupXX.infomaniak.com/identity/v3 export OS_REGION_NAME=RegionOne export OS_PROJECT_NAME=sb_project_SBI-XXXX export OS_PASSWORD='' export OS_USER_DOMAIN_NAME=default export OS_USERNAME=SBI-XXXX export OS_PROJECT_DOMAIN_NAME=default export RESTIC_REPOSITORY=swift:sb_project_SBI-XXXX:/ export RESTIC_PASSWORD_FILE=restickey" > resticconf
OS_AUTH_URL
URL to access the Swiss Backup cluster (1)OS_PROJECT_NAME
andOS_USERNAME
replace SBI-XXXX with your identifierOS_PASSWORD
replace with the password generated upon activationRESTIC_REPOSITORY
- replace SBI-XXXX with your identifier
- replace the
bucket name
with the name you want to give to your container that stores the backups
RESTIC_PASSWORD_FILE
replace with the full path to the file containing the encryption key
Load the Restic configuration by running the following command:
source resticconf
Initialize the bucket with the following command:
uid@h2:~$ ./restic -r $RESTIC_REPOSITORY init
(1) The indication "//swiss-backup02
", "//swiss-backup03
" etc. changes according to the cluster number indicated on the Manager in the Cloud storage information under "Location"; and if your Swiss Backup device was created before October 2020, you will need to use https://swiss-backup.infomaniak.com/identity/v3
Back up your files
To back up your files, simply run the following command:
uid@h2:~$ ./restic backup
#exemple pour sauvegarder l'ensemble d'un hébergement
uid@h2:~$ ./restic backup ./
#exemple pour sauvegarder le dossier sites
uid@h2:~$ ./restic backup sites/
The first snapshot takes a long time (several hours depending on the amount of data) because all files are copied, while subsequent ones will use the differential principle.
Backup the databases
Restic can read data from stdin to record a program's output.
Use the following command to back up an individual MySQL database:
mysqldump --databases nom_de_la_base_de_données -u utilisateur_de_la_base_de_données -p | restic backup --stdin --stdin-filename database_dump.sql
To back up all databases, run the mysqldump command to extract all databases from the server, then redirect the output to Restic:
mysqldump -u utilisateur_de_la_base_de_données -p --all-databases | restic backup --stdin --stdin-filename all_databases.sql
List backups
To list your backups, you can use the following command:
uid@h2:~$ ./restic snapshots
Restore a backup
You can restore a backup with the following command:
uid@h2:~$ ./restic restore --target
Automate
On Cloud Server, it is possible to add a cron job to automate the launch of the backup.
On shared hosting, this option is not available.