Compare commits

..

2 Commits

Author SHA1 Message Date
077ed7c9ca added gitignore
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-07-25 14:07:17 +01:00
54093db776 general improvements 2024-07-25 14:06:47 +01:00
4 changed files with 34 additions and 20 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.sw*

12
.woodpecker.yml Normal file
View File

@ -0,0 +1,12 @@
steps:
- name: build-image
image: woodpeckerci/plugin-docker-buildx
secrets: [docker_username, docker_password]
settings:
repo: wilw/fs-backup
dockerfile: Dockerfile
platforms: linux/arm64,linux/amd64
when:
- event: push
branch: main

View File

@ -1,25 +1,24 @@
# Filesystem Backup
# File/directory Backup
A simple script for backing up a directory periodically and securely using [Restic](https://restic.net).
This script backs-up a directory to an S3-compatible bucket (i.e. it doesn't have to be Amazon S3), with hourly snapshots.
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.
I call this `fs-backup` even though it works with files/directories on a filesystem (as opposed to `db-backup`), rather than the filesystem as a whole.
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:
```
version: '2'
services:
serverbackup:
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
@ -31,22 +30,22 @@ services:
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:
Also change the variables in the `environment` block to match what's needed for your chosen Restic backend. Refer to [the documentation](https://restic.readthedocs.io/en/stable/030_preparing_a_new_repo.html) for more information.
* AWS_ACCESS_KEY_ID: Use the access key provided by your bucket provider
* AWS_SECRET_ACCESS_KEY: Use the secret key provided by your bucket provider
* RESTIC_REPOSITORY: The repository name. For a Linode Object Storage bucket you can use `s3: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.
At a minimum we recommend setting the following:
You can now bring up the container: `docker-compose up -d`.
* `RESTIC_REPOSITORY`: The repository name. For a Linode Object Storage bucket you can use `s3: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 serverbackup /usr/bin/restic init
docker compose exec -it filebackup /usr/bin/restic init
```
## Defaults
@ -54,7 +53,7 @@ docker-compose exec serverbackup /usr/bin/restic init
The image `wilw/fs-backup` (which you can use as described above) does the following:
* Backs-up `/backupdir` hourly
* Keeps 24 hourly and 10 daily backups, and prunes the rest
* 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.
@ -71,10 +70,8 @@ Refer to [the documentation](https://restic.readthedocs.io/en/stable/030_prepari
## 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`.
AFAIK, you need a new bucket for each repository.
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](https://restic.readthedocs.io/en/stable/).
To learn more about Restic, restoring backups, management, and more, please refer to the [official documentation](https://restic.readthedocs.io/en/stable/).

View File

@ -1,7 +1,11 @@
#!/bin/sh
set -x # Print commands
set -e # Exit on error
set -u # Exit on undefined variable
# Perform the backup
/usr/bin/restic backup -q --host $RESTIC_HOSTNAME /backupdir
# Prune old backups
/usr/bin/restic forget -q --keep-hourly 24 --keep-daily 10 --prune
/usr/bin/restic forget -q --keep-hourly 24 --keep-daily 10 --keep-weekly 6 --keep-monthly 6 --prune