Creating backups with Restic and 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_KEY export 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:
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 want 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.
-
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 correct created new cache in /root/.cache/restic Files: 1 new, 0 changed, 0 unmodified Dirs: 1 new, 0 changed, 0 unmodified Added to the repo: 732 B processed 1 files, 22 B in 0:06 snapshot 15a39fd5 saved
-
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 correct ID Time Host Tags Paths --------------------------------------------------------------------------------- 15a39fd5 2022-04-06 14:39:25 scw-jovial-keldysh /root/my-directory 20eed69e 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, the following output displays:
enter password for repository: repository da8e38a1 opened successfully, password is correct restoring <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.
Visit our Help Center and find the answers to your most frequent questions.
Visit Help Center