#408: Backup and restore of Swarmica on your own equipment
Отредактирована: сегодняDescription
This article describes the procedure for backing up (backup) and restoring (restore) the Swarmica application installed on the customer's side (on-premise) using the standard functions of the basic operating system.
IMPORTANT! It is recommended to use specialized solutions for creating backups at the server level to ensure guaranteed data integrity and recovery speed after a failure.
This article provides minimal instructions for creating backups for recovery after a failure or data migration to another server without guaranteeing the recovery speed (RTO) for all data at the time of backup.
What needs to be saved:
- Configuration files located in the Swarmica installation folder (default
/root/swarmica) - Database (using Postgres)
- User files (Docker Volumes)
Creating a backup (backup)
Configuration files
Save the contents of the /root/swarmica folder:
tar -cvjf sw-backup-configs.tbz /root/swarmica\
/root/.docker/
Database
Run the pg_dump command in the swarmica-postgres container:
cd /root/swarmica
source .env
docker exec -it --env-file .env swarmica-postgres pg_dump -Fc --clean -U$POSTGRES_USER $POSTGRES_DB -f /backups/db.`date +%Y%m%d%H%M%S`.sql
If necessary, copy the dump file to the server (this may be necessary if you plan to restore only the database on another server, for example, for testing):
docker cp swarmica-postgres:/backups/db.YOURDATE.sql ./
User files
User data is stored in Docker Volumes with the following names:
- swarmica_ugc
- swarmica_runtime
- swarmica_cron_d
- swarmica_ai_assistant
To back up all files, run the following command:
tar -cvjf sw-backup-files.tbz \
/var/lib/docker/volumes/swarmica_swarmica_postgres_data_backups/_data/ \
/var/lib/docker/volumes/swarmica_swarmica_ugc/_data/ \
/var/lib/docker/volumes/swarmica_swarmica_runtime/_data/ \
/var/lib/docker/volumes/swarmica_ai_assistant/_data/
IMPORTANT! Make sure there is enough free space on the disk where you create the backup archive to accommodate all user data.
- Command to check free space
df -h - Command to check the size of user data
docker system df | grep Volumes
Restoring a backup (restore)
IMPORTANT! This procedure will completely restore ALL Swarmica data, including email settings - if you want to create a clone of the system for testing but not send notifications to existing users, be sure to change the Email configuration to FILE in the Settings > Swarmica Settings section
Before restoring a backup on another server, you must install all the required software for Swarmica to work.
apt-get update && \
apt-get install --no-install-recommends -y \
curl \
jq \
host \
python3 \
docker.io \
docker-compose-v2
dnf install -y \
curl \
jq \
bzip2 \
python3.12 \
docker-ce \
docker-compose
- Copy to the target server and unzip the archives created in the previous step:
tar -xvjf sw-backup-files.tbz -C /
tar -xvjf sw-backup-configs.tbz -C /
- Pull the container images:
cd /root/swarmica
docker compose pull
This step can be skipped if you are restoring data on the same server where the backup was created
- Start the Postgres container:
docker compose up -d postgres
- If you are restoring the database dump on a 'clean' installation, first copy it into the container:
docker cp db.YOURDATE.sql swarmica-postgres:/backups/
This step can be skipped if you are restoring data from a backup created following all steps in this article.
- Restore the dump:
cd /root/swarmica
source .env
docker exec -it --env-file .env swarmica-postgres pg_restore --if-exists --clean -U$POSTGRES_USER -d$POSTGRES_DB /backups/db.YOURDATE.sql
- Start the remaining containers:
docker compose up -d
- Perform the final procedures:
docker exec --env-file .env -it swarmica-django-1 python manage.py post_start