tenekev / immich-offline-files-remover

A drop-in solution for scheduled cleaning of Immich's External libraries. Just copy the docker-compose code in your Immich stack and configure it.
GNU Affero General Public License v3.0
3 stars 0 forks source link
docker docker-compose immich

🐳 Immich Auto Remove Offline Files - Docker Edition

This is a simple Pyhon script, dressed as a Docker container, that removes Offline Files from External Immich libraries. It can be used to either run the script manually, or via cronjob by providing a crontab expression to the container. The container can then be added to the Immich compose stack directly.

🔑 Obtaining an Immich API key

Instructions can be found in the Immich docs - Obtain the API key

🔂 Running once

To perform a manually triggered run, use the following command:

docker run --rm -e API_URL="https://immich.mydomain.com/api/" -e API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -e OFFLINE_THRESHOLD=100 ghcr.io/tenekev/immich-offline-files-remover:latest /script/immich_auto_remove_offline_files.sh

🔁 Running on a schedule

docker run --name immich-offline-files-remover -e TZ="Europe/Sofia" -e CRON_EXPRESSION="0 * * * *" -e API_URL="https://immich.mydomain.com/api/" -e API_KEY="xxxxx" -e OFFLINE_THRESHOLD=100 ghcr.io/tenekev/immich-offline-files-remover:latest

📃 Running as part of the Immich docker-compose.yml

Adding the container to Immich's docker-compose.yml file:

version: "3.8"
...
services:
  immich-server:
    container_name: immich_server
  ...

  immich-offline-files-remover:
    container_name: immich-offline-files-remover
    image: ghcr.io/tenekev/immich-offline-files-remover:latest
    restart: unless-stopped
    environment:
      API_URL: http://immich_server:3001/api
      API_KEY: xxxxxxxxxxxxxxxxx               # https://immich.app/docs/features/command-line-interface#obtain-the-api-key
      OFFLINE_THRESHOLD: 100                   # If the number of offline files exceed this number, they won't be cleaned. Indicates an issue with availability.
      CRON_EXPRESSION: "0 */1 * * *"           # Run every hour
      TZ: Europe/Sofia

You can still trigger the script manually by issuing the following command in the container shell:

/script/immich_auto_remove_offline_files.sh

Or with Docker exec:

docker exec -it immich-offline-files-remover /script/immich_auto_remove_offline_files.sh

License

This project is licensed under the GNU Affero General Public License version 3 (AGPLv3) to align with the licensing of Immich, which this script interacts with. For more details on the rights and obligations under this license, see the GNU licenses page.