Skip to content

Miccet.nl

Electronics, Arduino and Wireless communication

Menu
Menu

Backup docker volumes without root user

Posted on 2023-12-01 by miccet

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:

chuckcharlie/cups-avahi-airprint:latest

using this docker-compose.yaml file:

---
version: "2.1"
services:
  cups:
    network_mode: host
    image: chuckcharlie/cups-avahi-airprint:latest
    container_name: cups
    environment:
      - UUID=1000
      - GUID=1000
      - CUPSADMIN=admin
      - CUPSPASSWORD=password
    volumes:
      - ./services:/services
      - ./config:/config
    restart: unless-stopped

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")
mkdir ~/backup/files/$DATE

cd ~/cups
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.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • Backup docker volumes without root user
  • Replacing the hard drive on the Ubiquiti UniFi Cloud Key Gen2 with a WD Purple
  • Extra NIC on the HP thin client T630
  • Bind serial to HC-05
  • Wireguard

Recent Comments

  • Marco on Extra NIC on the HP thin client T630
  • MT on Extra NIC on the HP thin client T630
  • tinybull on Extra NIC on the HP thin client T630
  • Bind serial to HC-05 – Miccet.nl on HC-05 review
  • HM-10 review – Miccet.nl on HC-05 review

Archives

  • December 2023
  • July 2023
  • January 2023
  • April 2020
  • October 2019
  • July 2018

Categories

  • Batteries
  • Bluetooth
  • Docker
  • Servers
  • Uncategorized

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2025 Miccet.nl | Powered by Minimalist Blog WordPress Theme