Skip to content

Use cases

Niclas Lindstedt edited this page May 9, 2021 · 14 revisions

Backup files from a Docker volume

You have a Docker volume that you want to backup, but you can't/won't add the docker-backup image to that compose file.

Solution

Create a new docker-compose.yml file and reference the volume using external: true.

version: '3'

services:
  backup:
    image: niclaslindstedt/docker-backup:latest
    volumes:
      - nginx-config:/volumes/nginx-config
      - /mnt/data/backups:/backup
      - /mnt/nas/backups:/lts

volumes:
  nginx-config:
    external: true

The backup container will then create backups of the nginx-volume according to the cron schedule and place them in the /mnt/data/backups folder. The backups will then be copied (and pruned) for long-term storage to /mnt/nas/backups.

Backup files from another container

You have files inside a Docker container that you would like to backup.

Solution

You will first need to create a Docker volume and mount it to that container.

In the (stripped-down) example below, we add a volume called nginx-config inside /etc/nginx.

version: '3'

services:
  nginx:
    image: nginx:latest
    volumes:
      - nginx-config:/etc/nginx

  backup:
    image: niclaslindstedt/docker-backup:latest
    volumes:
      - nginx-config:/volumes/nginx-config
      - /mnt/data/backups:/backup
      - /mnt/nas/backups:/lts

volumes:
  nginx-config:

The backup container will then create backups of the nginx-volume according to the cron schedule and place them in the /mnt/data/backups folder. The backups will then be copied (and pruned) for long-term storage to /mnt/nas/backups.

Backup files from your host computer

You have files on your host computer that you wish to backup.

Solution

Create a new docker-compose.yml file and mount the host folder into the backup container.

version: '3'

services:
  backup:
    image: niclaslindstedt/docker-backup:latest
    volumes:
      - /home/niclas/Documents:/volumes/my-documents
      - /mnt/data/backups:/backup
      - /mnt/nas/backups:/lts

The backup container will then create backups of the /home/niclas/Documents folder according to the cron schedule and place them in the /mnt/data/backups folder. The backups will then be copied (and pruned) for long-term storage to /mnt/nas/backups.

Clone this wiki locally