Because of their scalability and high-availability, Buckets are a great option for storing backups.
Kopia is an open-source, fast and secure backup program for local directories or files. It uses encryption to protect your backups, ensuring that only you can access the data. For more information about Kopia, see:
-
Create your credentials
For a step-by-step guide, see the getting started article "Generating S3 credentials".
Make sure you save the credentials in a safe location right after you create them. You cannot view the secret key again, neither via Cloud Console nor via API.
-
Install Kopia
If you haven't already, install Kopia CLI now. You can follow the official instructions at kopia.io.
-
Store the Kopia password
You can use
apg
, the Advanced Password Generator, to create a random password. On Debian-based systems, you can install it withapt install apg
.apg -a 1 -m 32 -n 1 -M NCL
Copy the Kopia password from the output and save it locally.
-
Create a new repository
For this step, you need an existing Bucket (see the getting started "Creating a Bucket"). In the command below, replace
fsn1
with the location of your Bucket.Create a new repository:
kopia repository create s3 \ --access-key=<your_access_key> \ --secret-access-key=<your_secret_key> \ --endpoint=fsn1.your-objectstorage.com \ --region=fsn1 \ --bucket="<your_bucket_name>"
When it asks for a password, enter the password you just created. Kopia will use the password to encrypt your data.
Important: During a restore, you have to enter this password again to decrypt the data. Please store it in a safe place — without it, you won’t be able to access your Kopia backups.
After it was created, check if everything works as expected:
kopia repository validate-provider
It should return something like "All good."
You should automatically be connected to the new repository. To double-check if you're connected to the repository, run:
kopia repository status -t -s
At the top of the output you should see:
Storage config: { "bucket": "<your_bucket_name>", "endpoint": "fsn1.your-objectstorage.com", "accessKeyID": "<your_access_key>", "secretAccessKey": "*************". [...] }
At the bottom of the output you should see a command like this:
kopia repository connect from-config --token <token>
To disconnect, you would run
kopia repository disconnect
. After you disconnect from the repository, you can reconnect by providing the credentials and endpoint as you did when you created the repository. Alternatively you can reconnect by running the command from the output above which includes a token.To reconnect, you can use one of these options:
- Provide credentials and endpoint
kopia repository connect s3 \ --access-key=<your_access_key> \ --secret-access-key=<your_secret_key> \ --endpoint=fsn1.your-objectstorage.com \ --region=fsn1 \ --bucket=<your_bucket_name>
- Provide the token
kopia repository connect from-config --token <token>
- Provide credentials and endpoint
-
Create a backup
First, create a test file:
mkdir $HOME/test-repo echo "Content of test file." > $HOME/test-repo/test.txt
Now create a backup of the new test file. Before you run this command, make sure you're connected to your repository.
kopia snapshot create $HOME/test-repo kopia snapshot list $HOME/test-repo
The backup should show up in your Bucket.
-
View and restore backups
-
List all snapshots:
kopia snapshot list # Show identical snapshots (same snapshot ID) # kopia snapshot list -l
Example output:
holu@example:C:\Users\holu\test-repo <time_stamp> <snapshot-id> 48 B drwxrwxrwx files:1 dirs:1 <tags>
-
View files and directories in a specific snapshot:
kopia ls -l <snapshot-id>
Example output:
w-rw- 48 <time_stamp> 88cccae56419a116dfe37e03745f99f4 test.txt
-
Restore a snapshot
kopia snapshot restore <snapshot-id> <target-directory>
The target directory could be something like
$HOME/test-repo-restored
, for example. -
Delete a snapshot
kopia snapshot delete <snapshot-id> --delete
-
-
Setup automatic backups
You can use cron jobs to automate the creation of backups.
First, run
repository status
again to view the token that you need to reconnect:kopia repository status -t -s
Copy this command from the output, so that you can add it to the script:
kopia repository connect from-config --token <token>
Create a script, e.g.
$HOME/backup.sh
, and add the command from above:#!/bin/bash set -e # Connect to repository kopia repository connect from-config --token <token> # Create snapshots: kopia snapshot create $HOME/test-repo
Make the script executable:
chmod 700 $HOME/backup.sh
Run the script manually, to check if it works:
./backup.sh
If the snapshot shows up in the Bucket, you can setup the cron job:
crontab -e
And add this line:
0 0 * * * $HOME/backup.sh
This cron job will run the script every day at midnight.
* * * * * /path │ │ │ │ └───────────── Day of the week (0 - 6) │ │ │ └───────────── Month (1 - 12) │ │ └───────────── Day of the month (1 - 31) │ └───────────── Hour (0 - 23) └───────────── Minute (0 - 59)
Your data should now be backed up automatically.