Backup Docker Volumes

Hi Community,

I´m searching for an easy way to backup the static volumes created from docker. Is there any simple solution to get them without ssh into hostOS or removing the SD Card?
I´m thinking about some kind of script that saves all the data into a device folder on a remote ftp server or something like that.

If someone has any idea or hint how to start best, I would be very thankful!

best regards

1 Like

Hi @danielboe, I imagine you’d like to do this to be able to recover a device in the case of losing the SD card or something like that?

This is actually a feature we’d like to implement eventually, but it’s not yet being worked on. I think in the meantime, your idea of copying the data to a remote server could work.

I would probably recommend using scp, and setting up the authentication on the server so that each uuid has access to its own folder (so that you don’t risk an attacker getting all your backups if they compromise a single device). Dunno if anyone in the community has tried something like that.

You could adapt what’s described in this blogpost: https://bradmontgomery.net/blog/automatic-backups-with-cron-tar-and-ssh/ though it shows a slightly different scenario, where you scp from the machine where you want to keep the backup. You could do it either way, scp’ing from the device to the server or from the server to the device (though that would be equivalent to sshing into the device, which from your post is something you want to avoid).

For the authentication part, you could have a script in the server that detects when a device is provisioned, creates an ssh key pair, and passes the private key to the device by creating an environment variable on the balena API. Alternatively, you can open an API endpoint on the device and have the server query it to obtain the public key. There’s a few other options for this but it depends on what you’re already doing (e.g. are you already sending some other data from the device to the cloud? do you have other auth mechanisms already in place?) and what your security requirements look like.

2 Likes

Hi, just trying to solve same situation for my Home Assistant via Balena. What about adding another Docker container for just backu purpose? This can be used across all projects. Sure, you need to modify the docker-compose.yml but it can be a quite universal solution…

I did exactly this and it works fine for me with google drive. If you want I can share the sources. You just add the shared folders in the same mount for docker composer.
Edit: You can find the sources here:
https://bitbucket.org/danielboe/balena-smarthome/src/master/backup/
Its not documented from me at the moment. You can set:
FILE_LIMIT - number of revisions to keep
GDRIVE_FOLDER_ID - id of folder in google drive. You can see this ID in the browser URL in google drive online.

You need a File in your backup contaienr root for authentification before push the container (“token_v2.json”). Dont share this file. Here is an example how to create the token: Continuously Deploying GO app to google drive | by Mohammed Hewedy | Medium

best regards

Daniel