immich-app / immich

High performance self-hosted photo and video management solution.
https://immich.app
GNU Affero General Public License v3.0
49.41k stars 2.6k forks source link

iOS backup stops when app is not focused and the screen on #6902

Closed MattDahEpic closed 8 months ago

MattDahEpic commented 8 months ago

The bug

We are having trouble getting the backup functionality on iOS working reliably. It works fine whenever the screen is on and the app is focused, but stops as soon as you change apps (including pushing up into the app switcher) and stops when the screen times out and goes to sleep. When focused and screen on, the uploads work fine and show up on the server. The remaining uploads counts down as expected, shared users are able to see photos as they upload, etc. Everything seems fine there. The moment you switch apps or the screen goes to sleep the backup stops and never continues. Foreground backup only works when the screen is on and the app is focused, and the background backup seems like it has stated sometimes but never actually does anything. We only occasionally see the background upload notification, and when it is present it does not count up instead staying at whatever it started at.

We are logged in as a non-admin user. We have enabled Background App Refresh as detailed in the docs and both foreground and background backups are enabled. The Android app on another phone uploads fine. Running iOS 17.2.1.

The OS that Immich Server is running on

unRAID 6.12.6 w/ Docker Compose plugin

Version of Immich Server

v1.94.1

Version of Immich Mobile App

v1.94.1

Platform with the issue

Your docker-compose.yml content

version: "3.8"

services:
  immich-server:
    container_name: immich_server
    image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
    command: ["start.sh", "immich"]
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
      - /mnt/user/photos/old:/mnt/user/photos/old:ro
    env_file:
      - .env
    # ports:
    #   - 2283:3001
    depends_on:
      - redis
      - database
    restart: always
    networks:
      - reverseproxy

  immich-microservices:
    container_name: immich_microservices
    image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
    # extends: # uncomment this section for hardware acceleration - see https://immich.app/docs/features/hardware-transcoding
    #   file: hwaccel.transcoding.yml 
    #   service: cpu # set to one of [nvenc, quicksync, rkmpp, vaapi, vaapi-wsl] for accelerated transcoding
    command: ["start.sh", "microservices"]
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
      - /mnt/user/photos/old:/mnt/user/photos/old:ro
    env_file:
      - .env
    depends_on:
      - redis
      - database
    restart: always
    networks:
      - reverseproxy

  immich-machine-learning:
    container_name: immich_machine_learning
    # For hardware acceleration, add one of -[armnn, cuda, openvino] to the image tag.
    # Example tag: ${IMMICH_VERSION:-release}-cuda
    image: ghcr.io/immich-app/immich-machine-learning:${IMMICH_VERSION:-release}
    # extends: # uncomment this section for hardware acceleration - see https://immich.app/docs/features/ml-hardware-acceleration
    #   file: hwaccel.ml.yml
    #   service: cpu # set to one of [armnn, cuda, openvino, openvino-wsl] for accelerated inference - use the `-wsl` version for WSL2 where applicable
    volumes:
      - model-cache:/cache
    env_file:
      - .env
    restart: always
    networks:
      - reverseproxy

  redis:
    container_name: immich_redis
    image: redis:6.2-alpine@sha256:70a7a5b641117670beae0d80658430853896b5ef269ccf00d1827427e3263fa3
    restart: always
    networks:
      - reverseproxy

  database:
    container_name: immich_postgres
    image: tensorchord/pgvecto-rs:pg14-v0.1.11
    env_file:
      - .env
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_DB: ${DB_DATABASE_NAME}
    volumes:
      - pgdata:/var/lib/postgresql/data
    restart: always
    networks:
      - reverseproxy

  backup:
    container_name: immich_db_dumper
    image: prodrigestivill/postgres-backup-local
    env_file:
      - .env
    environment:
      POSTGRES_HOST: database
      POSTGRES_DB: ${DB_DATABASE_NAME}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      SCHEDULE: "@daily"
      BACKUP_NUM_KEEP: 7
      BACKUP_DIR: /db_dumps
    volumes:
      - /mnt/user/appdata/immich/db_dumps:/db_dumps
    depends_on:
      - database
    networks:
      - reverseproxy

volumes:
  pgdata:
  model-cache:

networks:
  reverseproxy:
    name: [removed]
    external: true

Your .env content

# You can find documentation for all the supported env variables at https://immich.app/docs/install/environment-variables

# The location where your uploaded files are stored
UPLOAD_LOCATION=/mnt/user/photos/immich

# The Immich version to use. You can pin this to a specific version like "v1.71.0"
IMMICH_VERSION=release

# Connection secrets for postgres. You should change these to random passwords
DB_PASSWORD=[removed]

# The values below this line do not need to be changed
###################################################################################
DB_HOSTNAME=immich_postgres
DB_USERNAME=postgres
DB_DATABASE_NAME=immich

REDIS_HOSTNAME=immich_redis

Reproduction steps

1. Install the app and log in
2. Navigate to the backup settings, enable foreground and background backup
3. Wait for a backup to start or trigger one, notice the pending items counting down
4. Push up to enter the app switcher, note how the backup stops increasing and doesn't continue no matter how long you stay in the app switcher
5. Switch to another app, wait a bit, then go back to Immich. Note that the backup remaining count hasn't decreased even when exiting and reentering the backup page. Upon reentering the backup should have restarted counting down
6. Let the phone sit on the backup page until the screen times out. Note the count right before the screen times out
7. Let the phone sit for a few minutes, long enough where you would be confident that several photos have been backed up
8. Wake the phone, note that the count is the exact same as the moment the phone fell asleep

Additional information

No response

bo0tzz commented 8 months ago

This is working as expected. The foreground backup can only run when the app is open, and the background task will run whenever iOS feels like it. Unfortunately we have no control over that.

aviv926 commented 8 months ago

A side solution is to create a routine that at a certain time (I set it at night) the application will open for X amount of time, back up all the files and close. This is what I did with Google Photos for a friend with an iPhone, I guess it will work here too.

zeeshanjavaid commented 1 week ago

A side solution is to create a routine that at a certain time (I set it at night) the application will open for X amount of time, back up all the files and close. This is what I did with Google Photos for a friend with an iPhone, I guess it will work here too.

Can you share iOS shortcut you created? How will app open if phone is locked at that time?