Skip to content

Use cases

Niclas Lindstedt edited this page May 10, 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.

Backup files to an FTP server

You want your long-term storage backups to be backed up to an FTP server instead of being copied to a local folder.

Solution

Create a volume using the curlftpfs plugin:

docker plugin install valuya/curlftpfs:next
docker volume create -d valuya/curlftpfs:next -o address=<ip:port> -o credentials=<user:password> ftp-volume

Now simply mount it at /lts in your backup container, and you're done.

version: '3'

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

volumes:
  ftp-volume:
    extenal: true

Limitations

This will only work if the FTP server's root corresponds to the /volumes directory (i.e. the FTP's server need to have subfolders that match the folders in the /volumes directory).

Clone this wiki locally