78 lines
2.9 KiB
YAML
78 lines
2.9 KiB
YAML
# Run once: docker compose -f docker-compose-init.yml up --build --force-recreate
|
|
|
|
services:
|
|
kopia_init:
|
|
image: kopia/kopia:latest
|
|
container_name: kopia_init
|
|
# Use the passwords from .env
|
|
environment:
|
|
- KOPIA_REPOSITORY_PASSWORD=${KOPIA_REPOSITORY_PASSWORD}
|
|
- PUID=1000
|
|
- PGID=1000
|
|
|
|
# Volumes MUST match the server setup so the repository is initialized in the correct place.
|
|
volumes:
|
|
- kopia_config:/app/config
|
|
- kopia_cache:/app/cache
|
|
- kopia_logs:/app/logs
|
|
- g:/kopia-backups:/app/repository # CRITICAL: This is where the repo will be created
|
|
|
|
# --- YOUR SOURCE DATA ---
|
|
# Maps your host's E:\installers and H:\immich-photos to specific paths inside the container.
|
|
# ':ro' (read-only) is a safety best practice.
|
|
- e:/installers:/source/installers:ro
|
|
- h:/immich-photos:/source/immich-photos:ro
|
|
|
|
# Override the default Kopia ENTRYPOINT to use the standard shell.
|
|
entrypoint: /bin/sh
|
|
|
|
# This command now runs 4 steps sequentially:
|
|
# 1. Create the repository.
|
|
# 2. Connect to it (so subsequent commands work).
|
|
# 3. SET POLICY for /source/installers (12h interval + retention).
|
|
# 4. SET POLICY for /source/immich-photos (12h interval + retention).
|
|
command:
|
|
- -c
|
|
- |
|
|
# 1. Create the Kopia Repository
|
|
echo 'Creating new Kopia repository at /app/repository...'
|
|
kopia repository create filesystem \
|
|
--path=/app/repository \
|
|
--password=${KOPIA_REPOSITORY_PASSWORD} \
|
|
&& \
|
|
# 2. Explicitly connect to the repository non-interactively.
|
|
# This is CRITICAL for the policy commands to work.
|
|
echo 'Connecting to repository non-interactively...' && \
|
|
kopia repository connect filesystem \
|
|
--path=/app/repository \
|
|
--password=${KOPIA_REPOSITORY_PASSWORD} \
|
|
&& \
|
|
# 3. SET POLICY for installers (Schedule: 12h)
|
|
# This does NOT run a snapshot. It just saves the schedule.
|
|
echo 'Setting 12-hour schedule for /source/installers...' && \
|
|
kopia policy set /source/installers \
|
|
--snapshot-interval 12h \
|
|
--keep-daily 7 \
|
|
--keep-weekly 4 \
|
|
--keep-monthly 12 \
|
|
--password=${KOPIA_REPOSITORY_PASSWORD} \
|
|
&& \
|
|
# 4. SET POLICY for immich-photos (Schedule: 12h)
|
|
echo 'Setting 12-hour schedule for /source/immich-photos...' && \
|
|
kopia policy set /source/immich-photos \
|
|
--snapshot-interval 12h \
|
|
--keep-daily 7 \
|
|
--keep-weekly 4 \
|
|
--keep-monthly 12 \
|
|
--password=${KOPIA_REPOSITORY_PASSWORD}
|
|
|
|
echo 'Initialization complete. Repository created and policies set.'
|
|
|
|
# Do not restart since it's a one-off command
|
|
restart: "no"
|
|
|
|
# Re-using the same Docker-managed volumes
|
|
volumes:
|
|
kopia_config:
|
|
kopia_cache:
|
|
kopia_logs:
|