Skip to content

Using Kopia to setup snapshot backups

Well, I've had this spare 4TB hard drive laying around that wasn't particularly doing much so I decided to attach it to my ubuntu server, and just set up Kopia so write snapshots of my Immich Upload folder to it. Basically just an extra layer of backup.

I formatted the external hardrive on my windows computer with NTFS. Eh, I wanted it to be compatible with Windows in case I want to be able to restart the snapshots from my windows computer.

Inatll ntfs support

sudo apt install ntfs-3g

We want this drive mounted to a permanent path, i.e. /mnt/external_drive

Let's get the ID of the drive

lsblk -o NAME,MOUNTPOINT,UUID,FSTYPE,SIZE

You should see something like this in the results

sde                                                                                                 3.6T
├─sde1                                                                                              128M
└─sde2 /mnt/external_drive                 3ED8D736D8D6EAE3                     ntfs                3.6T
sr0   

Note the sde2 and the UUID: 3ED8D736D8D6EAE3

You want to edit the static file system

sudo nano /etc/fstab

Add this line:

UUID=3ED8D736D8D6EAE3  /mnt/external_drive  ntfs-3g  defaults,uid=1000,gid=1000,nofail  0  2

Mount the drive now

sudo mount -a

or

sudo mount -a

If you get an error saying it was already mounted you need to unmount and mount again.

sudo umount /dev/sde2

Note, that sde2 is for me, check what yours is from the lsblk command.

Now for the fun part, let's install kopia with docker compose

docker-compose.yml
services:
  kopia:
    image: kopia/kopia:latest
    container_name: Kopia
    restart: unless-stopped
    ports:
      - 51515:51515  # Exposing the web UI
    command:
      - server
      - start
      - --disable-csrf-token-checks
      - --insecure
      - --address=0.0.0.0:51515
      - --server-username=${USERNAME}
      - --server-password=${SECRET_PASSWORD}
    environment:
      # Set repository password (optional, can be set during the UI process)
      KOPIA_PASSWORD: ${SECRET_PASSWORD}
      USER: ${USERNAME}
      TZ: America/Denver
    volumes:
      # Mount local folders needed by Kopia
      - /mnt/external_drive/kopia/kopia-repo:/repository  # External drive for repository
      - /mnt/md0/apps:/apps:ro  # Read-only access to /mnt/md0/apps
      # Possibly want a restore path if you want read-only to the data being backed-up
      - /mnt/md0/restore:/restore
      # You may want to add other folders like logs or configs if necessary
      - ./app/config:/app/config
      - ./app/cache:/app/cache
      - ./app/logs:/app/logs
      # Mount data directory to snapshot (adjust as needed)
      - ./data:/data:ro
      # Mount temporary directory for browsing snapshots
      - ./tmp:/tmp:shared
.env
USERNAME=thomas
SECRET_PASSWORD=password

set the username and password in a .env file next to this file.

Note the volumes

The docker server needs to have the local path where you want the repository mounted

     - /mnt/external_drive/kopia/kopia-repo:/repository

Secondly, you also need to mount whatever location you want to backup

In this case my RAID array is located at mnt/md0 and I have all my assets from apps stored in there so I want access to that entire folder.

      - /mnt/md0/apps:/apps:ro 

I put the ro in there because I absolutely don't want kopia messing with the files there other than reading them to copy them over.

Sign into the UI at http://192.168.4.142:51515/

Now set up a repository. Remember, the path to the repository is just /repository (what we set in docker compose).

Now when you create a new snapshot, point to the uploads folder, i.e. /apps/immich-app. Hit the estimate button so you know everything is configured right. It should tell you the size of that folder.

Comments