Skip to content

Backups VM data in SwissBackup using Restic

This tutorial aims to present the different steps to back up and restore data from your VMs in the SwissBackup infrastructure which replicates your data 3 times in our datacenters in Switzerland. The backup tool used is restic.

Note

Instead of infomaniak SwissBackup you can use your public cloud swift storage or any OpenStack Swift storage

Restic

Restic is an efficient and secure backup tool developed in Golang :

  1. Compatible with SwissBackup (OpenStack Swift backend)
  2. No complexe setup
  3. Only transfers detected changes to saved files / folders
  4. Uses robust cryptographic tools to ensure the integrity and security of your data
  5. Make sure you can restore your data when you need it
  6. Full opensource tool : restic official Github

SwissBackup account

You have 90 free days of SwissBackup product. You can easily create your account in the Infomaniak manager.

  1. Add a device:

  2. Choose Free storage space:

  3. See your Swiss Backup credentials:

Restic installation

Arch Linux

$ apk add restic

CentOS

$ yum install yum-plugin-copr

$ yum copr enable copart/restic

$ yum install restic

Debian

$ apt-get install restic

Fedora

$ dnf install restic

FreeBSD

$ pkg install restic

Ubuntu

$ apt-get install restic

openSUSE

$ zypper install restic

If you have a problem going through the official directories of the distributions listed above or you install on another distribution you can still install restic through the official binaries.

wget -O restic.bz2 https://github.com/restic/restic/releases/download/v0.12.0/restic_0.12.0_linux_amd64.bz2

bunzip2 restic.bz2

chmod +x restic

mv restic /usr/bin/

Verify restic install

$ restic version
restic 0.12.0 compiled with go1.15.8 on linux/amd64

Backup setup

Create an encryption key

You must first create an encryption key that will be used encrypt your data in our infrastructure. Please note that this encryption key can't be changed and in the event of its loss your data will no longer be readable.

Tips

To generate a strong key you can use the command $ openssl rand -base64 14

You must store this key in a single text file so that it can be read by restic when using it. For example:

$ echo <My-password> > /path/to/your/file/containing_the_key

Create the Restic configuration file:

Based on the credentials you received after the creation of your SwissBackup account, create for example the file /home/user/restic_credentials with the following content, replace the different variables accordingly to your credentials.

export OS_AUTH_URL=https://swift02-api.cloud.infomaniak.ch/identity/v3
export OS_REGION_NAME=RegionOne
export OS_PROJECT_NAME=sb_project_SBI-XXXX
export OS_PASSWORD=<SwissBackup 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:/<bucket name>
export RESTIC_PASSWORD_FILE=</path/to/your/file/containing_the_key>

Details:

OS_AUTH_URL: Url to access the SwissBackup cluster. https://swift02-api.cloud.infomaniak.ch/identity/v3 or https://swift01-api.cloud.infomaniak.ch/identity/v3

OS_PROJECT_NAME: SBI-XXX is your SwissBackup username provided by mail and on your manager

RESTIC_REPOSITORY: Bucket name is container in swift used to store data. Bucket name could be My_VM_name for example.

Source the restic configuration file

You can now load your credentials and initialize your directory to perform your first backup

source /home/user/restic_credentials

Initialise the repository

restic -r swift:sb_project_SBI-XXXX:/<bucket name> init

Launch your first backup in SwissBackup !

restic backup /path/to/folder/to/backup

list snapshots:

restic snapshots

Output example:

$ restic snapshots
repository aa122fb4 opened successfully, password is correct
ID        Time                 Host                   Tags        Paths
-----------------------------------------------------------------------
e4a5efe5  2021-07-17 15:51:17  node50252-env-0519885  /root/      /root
81ccf1c7  2021-07-17 15:52:04  node50252-env-0519885  /root/      /root
93fe4ac2  2021-07-17 15:52:42  node50252-env-0519885  /root/      /root
8542ab6b  2021-07-17 15:53:49  node50252-env-0519885  /root/      /root
479e18bb  2021-07-17 15:55:08  node50252-env-0519885  /root/      /root
fe37266f  2021-07-17 20:00:01  node50252-env-0519885  /root/      /root
001c4236  2021-07-18 16:12:23  node50252-env-0519885  /root/      /root
6eb3949a  2021-07-18 20:00:01  node50252-env-0519885  /root/      /root
cf41fc20  2021-07-19 20:00:01  node50252-env-0519885  /root/      /root
-----------------------------------------------------------------------
9 snapshots

You can back up your entire filesystem excluding system folders or categorize your backups by tag or machine name more details here: Restic backup doc

Tip

Load restic credentials

You must load your restic credentials before each backup / list / restore action.

source /path/to/restic/credentials

Folders backup:

restic backup /path/to/my/folder

Filesystem backup:

restic backup --one-file-system /

Restoration

List snapshots

restic snapshots

Take the id of the snapshot to restore

restic restore <snapshot-ID> --target </destination/folder/to/restore/data>

More details about restic restoration: Restic restoration doc

Back to top