The password is required to access the repository. If you lose the password, your data will be irrevocably lost.
Creating backups with Restic and Object Storage
- restic
- object-storage
Restic is a backup tool that allows you to back up your Linux, Windows, Mac, or BSD machines and send your backups to repositories via different storage protocols, including Object Storage.
In this tutorial, you learn how to backup a Scaleway Instance running on Ubuntu 20.04 using Restic and Object Storage.
Before you start
To complete the actions presented below, you must have:
- A Scaleway account logged into the console
- Owner status or IAM permissions allowing you to perform actions in the intended Organization
- An SSH key
- A valid API key
- An Instance running on Ubuntu Focal Fossa (20.04)
- Installed and configured the AWS-CLI to use with Scaleway Object Storage
- Created an Object Storage bucket
Installing Restic
- Connect to your Instance with SSH. In a terminal run:
ssh root@<your_instance_ip>
- Update the system and upgrade the software already installed on the Instance.
apt update && apt upgrade -y
- Install Restic.
apt-get install restic
- Ensure the installation was successful by checking the version.
restic version
Setting up the Object Storage repository
A repository is the storage space where your backups will be hosted. In this tutorial, we will use Scaleway Object Storage buckets to host our backups.
-
Set up your environment variables, if you have not done so yet. Replace
$SCW_ACCESS_KEY
and$SCW_SECRET_KEY
with their corresponding values.export AWS_ACCESS_KEY_ID=$SCW_ACCESS_KEYexport AWS_SECRET_ACCESS_KEY=$SCW_SECRET_KEY -
Initialize the repository using your bucket’s endpoint as a backend. Your bucket endpoint can be found in the Bucket settings tab under Bucket Information.
restic -r s3:https://s3.fr-par.scw.cloud/<bucket_name> init -
Enter a password for the repository and repeat it when prompted.
enter password for new repository:enter password again:ImportantTipRestic requests you to enter the password every time you perform actions on your repository. If you have configured automatic backups, you might want to set up an environment variable for your password.
An output displays, informing the name and path of your repository.
created restic repository da8e38a165 at s3:https://s3.fr-par.scw.cloud/<bucket_name>
Creating backups
-
Run the command below to create a backup. Include the path to your repository (in this example, the path is the endpoint of your bucket), and the path of the directory you wish to back up (
~/<my-directory>
in the example).restic -r s3:https://s3.fr-par.scw.cloud/<bucket_name> backup ~/<my-directory>The command above creates a snapshot of your directory and sends it to your repository. The snapshot is stored as an object in your bucket.
TipBy default, the backups you create are stored using
STANDARD
storage class. If you want to use a different storage class, you can add the-o s3.storage-class=<STORAGE_CLASS>
option to your command. For example:restic -r s3:https://s3.fr-par.scw.cloud/<bucket_name> backup -o s3.storage-class=ONEZONE_IA ~/<my-directory>
-
Enter the password for the repository when prompted.
enter password for repository:If the operation is successful, you will see the following output:
repository da8e38a1 opened successfully, password is correctcreated new cache in /root/.cache/resticFiles: 1 new, 0 changed, 0 unmodifiedDirs: 1 new, 0 changed, 0 unmodifiedAdded to the repo: 732 Bprocessed 1 files, 22 B in 0:06snapshot 15a39fd5 savedTipRestic does not offer a built-in tool for automated backups. Restic recommends using tools like systemd and cron to schedule backup runs. Learn more on the Restic documentation.
-
Run the following command to verify that the backup was successful:
aws s3api list-objects --bucket <bucket_name>Alternatively, you can access your bucket via the Scaleway console. You can find the snapshots of your directory in the
/snapshots
folder.
Restoring from backups
-
Retrieve a list of your snapshots to identify the ID of the snapshot you want to restore. Make sure you specify the path to your repository in the command.
restic snapshots -r s3:https://s3.fr-par.scw.cloud/<bucket_name>enter password for repository:repository da8e38a1 opened successfully, password is correctID Time Host Tags Paths---------------------------------------------------------------------------------15a39fd5 2022-04-06 14:39:25 scw-jovial-keldysh /root/my-directory20eed69e 2022-04-06 15:09:01 scw-jovial-keldysh /root/my-directory---------------------------------------------------------------------------------2 snapshots -
Run the command below to restore your backup. Specify the path to your repository and the target directory.
restic -r s3:https://s3.fr-par.scw.cloud/<bucket_name> restore 15a39fd5 --target ~/<my-directory>If the operation is successful, you see the following output:
enter password for repository:repository da8e38a1 opened successfully, password is correctrestoring <Snapshot 15a39fd5 of [/root/my-directory] at 2022-04-06 14:39:25.024340615 +0000 UTC by root@scw-jovial-keldysh> to /root/my-directory
Going further
Refer to the Restic documentation to discover other configuration options and tutorials.