I have a few docker containers running on my server and some of them have volumes that are bound to a corresponding folder in my home folder. For example, I run the image:
So running this container and setting up a printer creates files in both the services and the config folders. I tried to just tar these folders that are mapped to the folder they are in by issuing the following command:
tar -czf cups.tar.gz -C ~ cups
This resulted in the error message:
tar: cups/config/printers.conf: Cannot open: Permission denied
tar: cups/config/ppd/Brother.ppd: Cannot open: Permission denied
tar: Exiting with failure status due to previous errors
The issue is that the container runs as root within it and creates the files on my local file system with those permissions. I tried some things I found on the internet on the subject by setting the GUID and UUID, as well as the UID and GID but nothing really helped.
I ended up using this solution below to make it work. I have a folder called ~/backup/files and then I create a folder with today’s date and time and finally use rclone to move the files to Dropbox.
DATE=$(TZ="Europe/Stockholm" date +"%Y-%m-%d_%H-%M")
docker compose stop
docker run --rm --volumes-from cups -v ~/backup/files/$DATE:/backup ubuntu tar cf /backup/cups-config-$DATE.tar /config
docker run --rm --volumes-from cups -v ~/backup/files/$DATE:/backup ubuntu tar cf /backup/cups-services-$DATE.tar /services
docker compose up -d
I then end up with tar archives in my /backup/files/$DATE folder without permission issues and I don’t have to change permissions or involve root in any way.