Will Webberley
077ed7c9ca
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
|
||
---|---|---|
.nova | ||
.gitignore | ||
.woodpecker.yml | ||
backup.sh | ||
Dockerfile | ||
entry.sh | ||
README.md |
File/directory Backup
A simple script for backing up a directory periodically and securely using Restic.
This script backs-up a directory to any Restic backend that you can configure using environment variables. It creates a new snapshot once per hour.
Note: I call this fs-backup
even though it generally works with specific files/directories on a filesystem rather than the filesystem as a whole.
Usage
Simply write a docker-compose.yml
along the following lines:
services:
filebackup:
image: wilw/fs-backup
restart: always
volumes:
- /home/user:/backupdir
environment:
# ... Your Restic configuration. E.g.:
- AWS_ACCESS_KEY_ID=accesskey
- AWS_SECRET_ACCESS_KEY=secretaccesskey
- RESTIC_REPOSITORY=s3:endpoint/bucket
- RESTIC_PASSWORD=complexstring
- RESTIC_HOSTNAME=hostname
Before bringing the container up, please read the following:
The container will backup the directory mounted to /backupdir
. In the example above I am backing up a home directory, but change this to whatever you need.
Also change the variables in the environment
block to match what's needed for your chosen Restic backend. Refer to the documentation for more information.
At a minimum we recommend setting the following:
RESTIC_REPOSITORY
: The repository name. For a Linode Object Storage bucket you can uses3:eu-central-1.linodeobjects.com/bucket-name
. See below for other examples.RESTIC_PASSWORD
: The string used to encrypt/protect your data. Use a long complex string, and don't lose it (or you'll lose your backups)RESTIC_HOSTNAME
: Set this to an identifier for the machine. If you don't, the Docker container ID will be used, which changes on each startup, which isn't ideal.
You can now bring up the container: docker compose up -d
.
Important
After the container is launched for the first time, you'll need to initialize the repository. You only need to do this once for each repository. To do so, run the following:
docker compose exec -it filebackup /usr/bin/restic init
Defaults
The image wilw/fs-backup
(which you can use as described above) does the following:
- Backs-up
/backupdir
hourly - Keeps 24 hourly, 10 daily, 6 weekly, and 6 monthly backups, and prunes the rest
To change this behaviour, just edit the backup.sh
file and rebuild the image.
RESTIC_REPOSITORY
syntax
Many providers offer S3-compatible storage. Below are a few examples for help with setting the RESTIC_REPOSITORY
variable:
- Linode:
s3:eu-central-1.linodeobjects.com/bucket-name
- Amazon S3:
s3:s3.amazonaws.com/bucket-name
- Minio:
s3:http://localhost:9000/repo-name
- Wasabi:
s3:https://serviceURL/bucket-name
Refer to the documentation for more information.
Backup different directories
If you have multiple separate directories you need to backup, just launch several versions of the image by specifying a new service for each in your docker-compose.yml
. You could use the RESTIC_HOSTNAME
variable to differentiate between them.
More
To learn more about Restic, restoring backups, management, and more, please refer to the official documentation.