"no parent snapshot found, will read all files" and Kubernetes

Hi, and thanks for this excellent software.

Just for future reference: I spent many hours trying to resolve the issue with the message "no parent snapshot found, will read all files" when running backups from Kubernetes Pods (scheduled by a CronJob) targeting the same path.

Although the documentation (restic/doc/040_backup.rst at master · restic/restic · GitHub) mentions it, it took me some time to realize that snapshots are distinguished by both path and host.

Kubernetes, by default, uses the Pod name as the hostname, and since Pod names are random, this caused the issue. I resolved it by simply adding hostname: backup-node-foo to my Pod definition.

I thought it might be helpful to include this note in the documentation, as Kubernetes deployments are becoming increasingly common.

Keep up the great work!"

2 Likes

Thank you for pointing this out! Indeed, that is the proper way to solve that problem. One could also use the --host option to the backup command to set the hostname restic uses.

2 Likes

The same thing happens with docker-compose. For reference here’s the docker-compose.yml config I use which includes the hostname defined. which uses a third party docker container that has a couple of extra features (I think) but might work with the standard container

services:
  backup:
    image: mazzolino/restic
    # If you don't define the hostname restic can't find the parent snapshot
    hostname: docker
    restart: unless-stopped
    container_name: restic-backup
    environment:
      RUN_ON_STARTUP: "true"
      BACKUP_CRON: "0 30 3 * * *"
      RESTIC_REPOSITORY: s3:s3.amazonaws.com/bucketname
      RESTIC_PASSWORD: abc123abc123
      RESTIC_BACKUP_SOURCES: /var/www/ /srv/
      RESTIC_COMPRESSION: max
      RESTIC_PACK_SIZE: 64
      RESTIC_BACKUP_ARGS: >-
        --exclude /docker/.git
        --exclude /srv/mysql/data
        --exclude /var/www/archive
      RESTIC_FORGET_ARGS: >-
        --keep-last 10
        --keep-daily 7
        --keep-weekly 8
        --keep-monthly 24
      AWS_ACCESS_KEY_ID: AKIAxxxx
      AWS_SECRET_ACCESS_KEY: xxxx
      TZ: Pacific/Auckland
      PRE_COMMANDS: |-
        # Do a database dump before the backup
        docker exec mysql mysqldump -u username -h 127.0.0.1 db_name > /srv/backups/backupname.sql
    volumes:
      # local:container (reminder)
      - /docker/:/docker/:ro
      - /srv/:/srv/
      - /var/www/:/var/www/:ro
      # This allows the container to interact with docker on the host machine
      - /var/run/docker.sock:/var/run/docker.sock

Yes, it occurs for every container-based architecture.

I finally used only the ‘–host’ option as proposed by Rawtaz bellow to avoid messing with the K8S manifests. I confirm that this option is enough to fix the problem.