Skip to content
/ backup Public

How to make a backup with nextcloud, restic and hetzner storagebox in container based manner

License

Notifications You must be signed in to change notification settings

realAP/backup

Repository files navigation

Pipeline Docker Image Version

backup

Use this image to load your data from a provider into your binded folder. This folder will be used as input for restic. Restic creates a backup and upload it to your sftp host. You can configure a cron job to run the backup every day at a specific time and telegram will be used to send status reports. All of it in a container based manner.

Overview

backup_overview.drawio.svg

Prerequisite

These things are needed:

  • Provider (Nextcloud, PostgreSQL, None)
  • SFTP Server to store (e.g. Hetzner Storagebox)
  • Docker
  • a device where backup is running

Configuration

1. Bind
Restic looks for a folder /source to back up data. The behavior of this folder depends on the mode you select at the beginning of the script:

  • Bind Mounting:

    • You can mount a folder from the host system into /source.
    • This approach is recommended because the data is persistent even if the container is deleted.
  • Internal Folder:

    • If no folder is mounted, the /source directory exists within the container.
    • Warning: By default the container deletes itself after it stops. Any data stored in the container's /source directory will be lost.

2. Provider
The provider mode dynamically writes data into the /source directory before restic creates a backup. This mode is useful when the data is generated by another service or application.

Providers currently supported:

  • Nextcloud: Synchronizes files into /source.
  • PostgreSQL: Dumps database content into /source.
  • None: No additional data is written to /source.

3. Environment Variables

There is a .env file where you can set all needed variables. It describes every variable and provides an example value.

How to backup

1. Place your public key at the sftp server and use the private key to log into it.

When used with Hetzner Storagebox, follow this guide

Currently, the private key should not have a password, it is not supported yet.

2. Download the script and .env file

  • curl -O https://raw.githubusercontent.com/realAP/backup/main/run_backup.sh
  • curl -0 https://raw.githubusercontent.com/realAP/backup/main/.env
  • make the script executable chmod +x run_backup.sh

3. Set .env file

Fill all needed variables in the .env file, it is provided with example values.

4. Run Backup

Just run the script ./run_backup.sh the backup will immediately start and repeat every day at 1am (default). For the first run, the script will initialize the restic repository.

Restore data

Just work as you would do it with restic.

Example: to get the latest snapshot from your data

  • ./run_backup.sh restore latest --target /restore
    • this will restore the latest snapshot to the /restore folder in the container which is binded to the host

as target use /restore to restore the data to the binded folder. For more information read the .env file example

Operations

You can use the script in two ways:

  1. Default is running the script without any arguments. As shown in the example above.
    • e.g. ./run_backup.sh
  2. With arguments. Use the script as you would use restic. The script will run the container in which restic is started and places every argument behind it. You have access to all the environment variables set in the .env file. Remember /restore is always binded to the host. And /source folder is binded to the host when not set to none.
    • ./run_backup.sh snapshots
    • ./run_backup.sh init
    • and more...

    Attention: the script will run the container which will be deleted after the command is executed. The data in the container is lost.


Debugging

When you want to debug the container you can run the container in interactive mode. Just run the script as follows ./run_backup.sh DEBUG and the container will start in interactive mode. This is just used in the development phase.

Logging

You can bind the /var/log folder to your host to get the logs. For this set the SCRIPT_LOG_PATH variable in the .env file. When the variable is not set then log files will be stored in the container. This is just for debugging purposes.

Why | Motivation

I have used https://duplicati.com/ which i can recommend. My problem is duplicati is not supported for my hardware anymore. This is the reason for this project.

I have nextcloud hosted by hetzner (https://www.hetzner.com/storage/storage-share/) and storagebox (https://www.hetzner.com/storage/storage-box/) a sftp hosted platform. The backup should work without hetzner it just needs a nextcloud server and sftp access.

Example for Provider Nextcloud

backup_overview_nextcloud.svg

  • TBD

Example for Provider PostgreSQL

backup_overview_postgres.svg

  • TBD

About

How to make a backup with nextcloud, restic and hetzner storagebox in container based manner

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published