I wrote this procedure a while ago:
Backup Process
0) ssh to machine and enter the chirpstack-docker folder
$ ssh <user>@<chirpstack-server>
$ cd chirpstack-docker
1) Ensure Docker is down so no containers try to write while backup occurs.
$ sudo docker compose down
2) Copy redis data dump
$ sudo cp /var/lib/docker/volumes/chirpstack-docker_redisdata/_data/dump.rdb redisbackup.rdb
3) Create a file for psql backup dump
$ touch postgresbackup
4) Start only the postgres container
$ sudo docker compose up postgres -d
5) dump all sql backup commands from container and pipe into backup file
$ sudo docker exec -it chirpstack-docker-postgres-1 pg_dumpall -c --no-password -h localhost -U postgres > postgresbackup
Restoral process
0) ssh to machine and enter chirpstack-docker folder
$ ssh <user>@<chirpstack-server>
$ cd chirpstack-docker
1) Ensure Docker is down so no containers try to write while backup occurs.
$ sudo docker compose down
2) Make a copy of current redis database (As a safe measure)
$ sudo cp /var/lib/docker/volumes/chirpstack-docker_redisdata/_data/dump.rdb redisdatareplaced.rdb
3) Delete old data dump and copy backup into volume
$ sudo rm /var/lib/docker/volumes/chirpstack-docker_redisdata/_data/dump.rdb
$ sudo cp redisbackup.rdb /var/lib/docker/volumes/chirpstack-docker_redisdata/_data/dump.rdb
4) Change permissions of new dump file
$ sudo chown lxd:<user>l /var/lib/docker/volumes/chirpstack-docker_redisdata/_data/dump.rdb
$ sudo chmod 600 /var/lib/docker/volumes/chirpstack-docker_redisdata/_data/dump.rdb
5) Start only postgres containers
$ sudo docker compose up postgres -d
6) Rebuild SQL database from backup
$ sudo docker compose exec -T postgres psql -h localhost -U postgres < postgresbackup
Although I’m fairly certain I’ve seen slightly cleaner ways since (the idea is still the same though, copy the redis data dump, and pg_dump the psql database) but I almost feel like I saw a built in command to automate the process or something similar.
If you’re coming from V3 you will also have to do the v3 to v4 migration process, or if starting from scratch the [release] ChirpStack v4.7 redis to postgres device session migration after your backup.