Backup Senaite running with docker on an Ubuntu Server, my solution!

Hey Guys,

I’m working for a startup and was looking for a LIMS system. During this search, I came across Senaite. However, I didn’t find a built-in backup solution in the system, so I started trying to back it up using the shell.

In my initial attempts, there were mistakes, but now I think I’ve found a solution by using these commands. I’m running Senaite on an Ubuntu server in a Docker container.

For Backup:

# Create a backup on a USB drive, replace "YOURCONTAINERID" with the ID of the container you want to back up

CONTAINER_ID="YOURCONTAINERID" && BACKUP_NAME="limsbackup-$(date +%Y%m%d)" && mkdir -p ~/media/external && sudo mount /dev/sdb1 ~/media/external && docker commit $CONTAINER_ID $BACKUP_NAME && sudo docker save -o ~/media/external/$BACKUP_NAME.tar $BACKUP_NAME && VOLUMES=$(docker inspect -f '{{ range .Mounts }}{{ .Source }}{{ end }}' $CONTAINER_ID) && for VOLUME in $VOLUMES; do if [ -n "$VOLUME" ]; then sudo tar -czvf ~/media/external/$(basename $VOLUME).tar.gz -C $VOLUME .; fi; done && sudo umount /dev/sdb1 && docker rmi $BACKUP_NAME

For Restore:

# Restore the backup from a USB drive, replace "YOURFILENAME" with the name of the backup file without the .tar extension

BACKUP_NAME="YOURFILENAME)" && mkdir -p ~/media/external && sudo mount /dev/sdb1 ~/media/external && docker load -i ~/media/external/$BACKUP_NAME.tar && CONTAINER_ID=$(docker run -d --name temp-container $BACKUP_NAME) && VOLUMES=$(docker inspect -f '{{ range .Mounts }}{{ .Source }}{{ end }}' $CONTAINER_ID) && docker stop temp-container && docker rm temp-container && for VOLUME in $VOLUMES; do if [ -n "$VOLUME" ]; then sudo tar -xzf ~/media/external/$(basename $VOLUME).tar.gz -C $VOLUME; fi; done && docker run -d --restart=unless-stopped -p 8080:8080 --name lims-restore -v /var/snap/docker/common/var-lib-docker/volumes/4e79f29f3622cf05ad63d883c8d4fa0bebd47c3ecdcd0fd00cfd599322c2d823/_data:/data $BACKUP_NAME && sudo umount /dev/sdb1

I tested this by removing the containers, images, and linked volumes, and the data restoration worked. However, I haven’t tested it on a clean system yet. Do you see any issues with this workaround? Or could this be a viable backup solution?

1 Like

Tried it yesterday on a clean System. unfortunatly it didn’t worked there. Seems there are files or links which have not been identified.
If someone have an idea where to look or how to manage it with a docker container…