This guide explains how to back up and restore Docker volumes on Linux. This guide assumes you are using the Koios service script detailed here.
Linux
This guide will only work on a Linux host. If you are running Koios on Windows or MacOS, make sure to backup these folders using your OS specific file locations and commands, or use Docker’s guide: https://docs.docker.com/engine/storage/volumes/#back-up-restore-or-migrate-data-volumes.
Volumes to Back Up
The Koios container uses the following volumes:
koios_data_postgres:
/var/lib/postgresql/16/main
koios_data_influxdb:
/root/.influxdbv2
koios_media:
/var/www/koios/media
koios_logs:
/var/www/koios/logs
koios_certs:
/var/www/koios/certs
koios_license:
/var/www/koios/license
Prerequisites
Ensure you have
docker
installed and running.Have sufficient disk space for the backup files.
Use a directory on the host system (e.g.,
/backups
) to store the backups.
Backing Up Volumes
To back up the volumes, we'll create a tarball for each volume's contents.
1. Create a Backup Directory
mkdir -p /backups/docker_volumes
2. Back Up Each Volume
Use the following command to back up each volume to a tarball:
sudo tar -czf /backups/docker_volumes/koios_data_postgres.tar.gz -C /var/lib/docker/volumes/koios_data_postgres/_data .
sudo tar -czf /backups/docker_volumes/koios_data_influxdb.tar.gz -C /var/lib/docker/volumes/koios_data_influxdb/_data .
sudo tar -czf /backups/docker_volumes/koios_media.tar.gz -C /var/lib/docker/volumes/koios_media/_data .
sudo tar -czf /backups/docker_volumes/koios_logs.tar.gz -C /var/lib/docker/volumes/koios_logs/_data .
sudo tar -czf /backups/docker_volumes/koios_certs.tar.gz -C /var/lib/docker/volumes/koios_certs/_data .
sudo tar -czf /backups/docker_volumes/koios_license.tar.gz -C /var/lib/docker/volumes/koios_license/_data .
3. Verify Backups
List the backup files to ensure they were created successfully:
ls -lh /backups/docker_volumes
Restoring Volumes
To restore the volumes, we'll extract the tarball contents back into the corresponding Docker volumes.
1. Restore Each Volume
Use the following command to restore each volume:
sudo tar -xzf /backups/docker_volumes/koios_data_postgres.tar.gz -C /var/lib/docker/volumes/koios_data_postgres/_data
sudo tar -xzf /backups/docker_volumes/koios_data_influxdb.tar.gz -C /var/lib/docker/volumes/koios_data_influxdb/_data
sudo tar -xzf /backups/docker_volumes/koios_media.tar.gz -C /var/lib/docker/volumes/koios_media/_data
sudo tar -xzf /backups/docker_volumes/koios_logs.tar.gz -C /var/lib/docker/volumes/koios_logs/_data
sudo tar -xzf /backups/docker_volumes/koios_certs.tar.gz -C /var/lib/docker/volumes/koios_certs/_data
sudo tar -xzf /backups/docker_volumes/koios_license.tar.gz -C /var/lib/docker/volumes/koios_license/_data
2. Verify Restored Data
You can verify the data restoration by starting the container and checking to see if your data looks correct:
sudo service docker.koios start
Tips
Automate Backups: Create a script to automate the backup process for all volumes.
Backup Location: Store backups in a safe location, such as an external drive or cloud storage.
Schedule Backups: Use
cron
or another task scheduler to back up volumes periodically.Test Restorations: Regularly test restoring volumes to ensure backups are functional.
By following this guide, you can reliably back up and restore your Docker volumes to maintain application data integrity.