This restores a backup from an Offen backup tar file.
Assumptions
- The docker compose file is in a directory:
/srv/docker/<project name> - The name of the Offen service in the compose file is:
<project name>-backup
The Script
Usage: restore-backup.sh <folder in /srv/docker> <volume name> <backup file path>
Example: ./restore-backup.sh n8n n8n_n8n_data ../n8n/backup-2025-12-26T00-00-00.tar.gz
# Save the script dir for later when we need to reference the expanded backup files
script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
# Restore the specified backup to a temp directory
rm -rf ./tmp
mkdir tmp
tar -C ./tmp/ -xvf "$3"
# Create a backup of the current state
cd /srv/docker/$1
docker exec $1-backup backup
docker compose down
# Delete the volume contents
docker run --rm -v $2:/data/ alpine /bin/sh -c "rm -rf /data/*"
# Create a container to copy the files to the backup data to the Docker volume
# Map the volume to the backup_restore folder of the alpine container.
docker run -d --name temp_backup_restore -v $2:/backup_restore alpine
# Copy the backup contents to the backup_restore folder which then writes to the Docker volume.
docker cp $script_dir/tmp/backup/my-app-backup/. temp_backup_restore:/backup_restore
# Clean up
docker stop temp_backup_restore
docker rm temp_backup_restore
# Start containers
docker compose up -d
Note: I don’t know why Offen uses the “my-app-backup” folder in the backup path. I don’t set that anywhere in my Docker compose file or the Offen config file. This might be different for you.