The phone cannot be backed up in the background #4229

Closed
opened 2026-02-05 09:54:14 +03:00 by OVERLORD · 20 comments
Owner

Originally created by @iGwkang on GitHub (Sep 5, 2024).

The bug

I have the same problem on both Android and iOS, when the app is in the foreground the backup works fine, but as soon as it switches to the background the app backup stops and the network seems to be disconnected.

phone: OnePlus ACE3, Realme GT Neo5, iPhone 14 Pro Max
system: Android 14 and iOS 16

The OS that Immich Server is running on

Debian, Docker version 26.1.4

Version of Immich Server

v1.113.1

Version of Immich Mobile App

v1.113.1

Platform with the issue

  • Server
  • Web
  • Mobile

Your docker-compose.yml content

#
# WARNING: Make sure to use the docker-compose.yml of the current release:
#
# https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml
#
# The compose file on main may not be compatible with the latest release.
#

name: immich

services:
  immich-server:
    container_name: immich_server
    image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
    # extends:
    #   file: hwaccel.transcoding.yml
    #   service: cpu # set to one of [nvenc, quicksync, rkmpp, vaapi, vaapi-wsl] for accelerated transcoding
    volumes:
      # Do not edit the next line. If you want to change the media storage location on your system, edit the value of UPLOAD_LOCATION in the .env file
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
    env_file:
      - .env
    ports:
      - 2283:3001
    depends_on:
      - redis
      - database
    restart: always
    healthcheck:
      disable: false

  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
    healthcheck:
      disable: false

  redis:
    container_name: immich_redis
    image: docker.io/redis:6.2-alpine@sha256:e3b17ba9479deec4b7d1eeec1548a253acc5374d68d3b27937fcfe4df8d18c7e
    healthcheck:
      test: redis-cli ping || exit 1
    restart: always

  database:
    container_name: immich_postgres
    image: docker.io/tensorchord/pgvecto-rs:pg14-v0.2.0@sha256:90724186f0a3517cf6914295b5ab410db9ce23190a2d9d0b9dd6463e3fa298f0
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_DB: ${DB_DATABASE_NAME}
      POSTGRES_INITDB_ARGS: '--data-checksums'
    volumes:
      # Do not edit the next line. If you want to change the database storage location on your system, edit the value of DB_DATA_LOCATION in the .env file
      - ${DB_DATA_LOCATION}:/var/lib/postgresql/data
    healthcheck:
      test: pg_isready --dbname='${DB_DATABASE_NAME}' --username='${DB_USERNAME}' || exit 1; Chksum="$$(psql --dbname='${DB_DATABASE_NAME}' --username='${DB_USERNAME}' --tuples-only --no-align --command='SELECT COALESCE(SUM(checksum_failures), 0) FROM pg_stat_database')"; echo "checksum failure count is $$Chksum"; [ "$$Chksum" = '0' ] || exit 1
      interval: 5m
      start_interval: 30s
      start_period: 5m
    command: ["postgres", "-c", "shared_preload_libraries=vectors.so", "-c", 'search_path="$$user", public, vectors', "-c", "logging_collector=on", "-c", "max_wal_size=2GB", "-c", "shared_buffers=512MB", "-c", "wal_compression=on"]
    restart: always

volumes:
  model-cache:

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=../share/immich
# The location where your database files are stored
DB_DATA_LOCATION=./postgres

# To set a timezone, uncomment the next line and change Etc/UTC to a TZ identifier from this list: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
# TZ=Etc/UTC

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

# Connection secret for postgres. You should change it to a random password
# Please use only the characters `A-Za-z0-9`, without special characters or spaces
DB_PASSWORD=postgres_immich

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

Reproduction steps

  1. Set the app to fully allow background use and ignore battery options
  2. Select the backup directory, then turn on foreground backup and background backup
  3. Switch the app to the background
  4. The backup stops after about 5 seconds, and there is no traffic on the mobile phone network. Switch immich back to the foreground again, and the backup will continue.

Relevant log output

No response

Additional information

No response

Originally created by @iGwkang on GitHub (Sep 5, 2024). ### The bug I have the same problem on both Android and iOS, when the app is in the foreground the backup works fine, but as soon as it switches to the background the app backup stops and the network seems to be disconnected. phone: OnePlus ACE3, Realme GT Neo5, iPhone 14 Pro Max system: Android 14 and iOS 16 ### The OS that Immich Server is running on Debian, Docker version 26.1.4 ### Version of Immich Server v1.113.1 ### Version of Immich Mobile App v1.113.1 ### Platform with the issue - [ ] Server - [ ] Web - [X] Mobile ### Your docker-compose.yml content ```YAML # # WARNING: Make sure to use the docker-compose.yml of the current release: # # https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml # # The compose file on main may not be compatible with the latest release. # name: immich services: immich-server: container_name: immich_server image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release} # extends: # file: hwaccel.transcoding.yml # service: cpu # set to one of [nvenc, quicksync, rkmpp, vaapi, vaapi-wsl] for accelerated transcoding volumes: # Do not edit the next line. If you want to change the media storage location on your system, edit the value of UPLOAD_LOCATION in the .env file - ${UPLOAD_LOCATION}:/usr/src/app/upload - /etc/localtime:/etc/localtime:ro env_file: - .env ports: - 2283:3001 depends_on: - redis - database restart: always healthcheck: disable: false 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 healthcheck: disable: false redis: container_name: immich_redis image: docker.io/redis:6.2-alpine@sha256:e3b17ba9479deec4b7d1eeec1548a253acc5374d68d3b27937fcfe4df8d18c7e healthcheck: test: redis-cli ping || exit 1 restart: always database: container_name: immich_postgres image: docker.io/tensorchord/pgvecto-rs:pg14-v0.2.0@sha256:90724186f0a3517cf6914295b5ab410db9ce23190a2d9d0b9dd6463e3fa298f0 environment: POSTGRES_PASSWORD: ${DB_PASSWORD} POSTGRES_USER: ${DB_USERNAME} POSTGRES_DB: ${DB_DATABASE_NAME} POSTGRES_INITDB_ARGS: '--data-checksums' volumes: # Do not edit the next line. If you want to change the database storage location on your system, edit the value of DB_DATA_LOCATION in the .env file - ${DB_DATA_LOCATION}:/var/lib/postgresql/data healthcheck: test: pg_isready --dbname='${DB_DATABASE_NAME}' --username='${DB_USERNAME}' || exit 1; Chksum="$$(psql --dbname='${DB_DATABASE_NAME}' --username='${DB_USERNAME}' --tuples-only --no-align --command='SELECT COALESCE(SUM(checksum_failures), 0) FROM pg_stat_database')"; echo "checksum failure count is $$Chksum"; [ "$$Chksum" = '0' ] || exit 1 interval: 5m start_interval: 30s start_period: 5m command: ["postgres", "-c", "shared_preload_libraries=vectors.so", "-c", 'search_path="$$user", public, vectors', "-c", "logging_collector=on", "-c", "max_wal_size=2GB", "-c", "shared_buffers=512MB", "-c", "wal_compression=on"] restart: always volumes: model-cache: ``` ### Your .env content ```Shell # 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=../share/immich # The location where your database files are stored DB_DATA_LOCATION=./postgres # To set a timezone, uncomment the next line and change Etc/UTC to a TZ identifier from this list: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List # TZ=Etc/UTC # The Immich version to use. You can pin this to a specific version like "v1.71.0" IMMICH_VERSION=release # Connection secret for postgres. You should change it to a random password # Please use only the characters `A-Za-z0-9`, without special characters or spaces DB_PASSWORD=postgres_immich # The values below this line do not need to be changed ################################################################################### DB_USERNAME=postgres DB_DATABASE_NAME=immich ``` ### Reproduction steps 1. Set the app to fully allow background use and ignore battery options 2. Select the backup directory, then turn on foreground backup and background backup 3. Switch the app to the background 4. The backup stops after about 5 seconds, and there is no traffic on the mobile phone network. Switch immich back to the foreground again, and the backup will continue. ### Relevant log output _No response_ ### Additional information _No response_
Author
Owner

@bo0tzz commented on GitHub (Sep 5, 2024):

The background backup isn't a process that continues running when you send the app to the background, but something that gets triggered separately, for example when you take a new photo.

@bo0tzz commented on GitHub (Sep 5, 2024): The background backup isn't a process that continues running when you send the app to the background, but something that gets triggered separately, for example when you take a new photo.
Author
Owner

@iGwkang commented on GitHub (Sep 5, 2024):

@bo0tzz Is there a way to make the app back up in the background?

@iGwkang commented on GitHub (Sep 5, 2024): @bo0tzz Is there a way to make the app back up in the background?
Author
Owner

@bo0tzz commented on GitHub (Sep 5, 2024):

Like I mentioned, the app will run background backup when triggered by the OS. For a first/large upload you'll need to use the foreground backup.

@bo0tzz commented on GitHub (Sep 5, 2024): Like I mentioned, the app will run background backup when triggered by the OS. For a first/large upload you'll need to use the foreground backup.
Author
Owner

@iGwkang commented on GitHub (Sep 5, 2024):

@bo0tzz I want to know why we should handle it this way. It's torture for first-time users, because the first time you use immich, there will be a lot of data to upload.

@iGwkang commented on GitHub (Sep 5, 2024): @bo0tzz I want to know why we should handle it this way. It's torture for first-time users, because the first time you use immich, there will be a lot of data to upload.
Author
Owner

@alextran1502 commented on GitHub (Sep 5, 2024):

@iGwkang the way it works is not by choice but by the OS constraints. You can read more here https://immich.app/docs/FAQ#why-is-background-backup-on-ios-not-working

Foreground backup will keep the screen stay on so I don't think it is a torture 😅

@alextran1502 commented on GitHub (Sep 5, 2024): @iGwkang the way it works is not by choice but by the OS constraints. You can read more here https://immich.app/docs/FAQ#why-is-background-backup-on-ios-not-working Foreground backup will keep the screen stay on so I don't think it is a torture 😅
Author
Owner

@iGwkang commented on GitHub (Sep 5, 2024):

@alextran1502 What I don't understand is why should I stop the current backup when the app application switches to the background? It's my first time to use immich, and I have 200G of data to back up. Do I have to leave immich at the front desk for dozens of hours with the screen on? What bad design is this? It is a kind of torture for the first-time users, you can't deny it!

@iGwkang commented on GitHub (Sep 5, 2024): @alextran1502 What I don't understand is why should I stop the current backup when the app application switches to the background? It's my first time to use immich, and I have 200G of data to back up. Do I have to leave immich at the front desk for dozens of hours with the screen on? What bad design is this? It is a kind of torture for the first-time users, you can't deny it!
Author
Owner

@bo0tzz commented on GitHub (Sep 5, 2024):

@iGwkang you're talking as if you're mad at us for deliberately designing things in a way that hurts you, when like Alex mentioned we're simply limited by what the OS lets us do. We're not who you should be mad at.

@bo0tzz commented on GitHub (Sep 5, 2024): @iGwkang you're talking as if you're mad at us for deliberately designing things in a way that hurts you, when like Alex mentioned we're simply limited by what the OS lets us do. We're not who you should be mad at.
Author
Owner

@iGwkang commented on GitHub (Sep 5, 2024):

Okay, sorry.
Because it took me a long time to find a solution, because I have opened all the background permissions, but still can't solve it. Because most other apps can continue to run in the background, but immich can't.

@iGwkang commented on GitHub (Sep 5, 2024): Okay, sorry. Because it took me a long time to find a solution, because I have opened all the background permissions, but still can't solve it. Because most other apps can continue to run in the background, but immich can't.
Author
Owner

@alextran1502 commented on GitHub (Sep 5, 2024):

@iGwkang The OS kills the foreground task, not that we want to terminate it 😅. When you put your application in the background, the OS will start scheduling when the background task can run.

Because most other apps can continue to run in the background, but immich can't.

This is not true. Immich can run in the background when the OS allows it to. Can you provide an example of other apps?

@alextran1502 commented on GitHub (Sep 5, 2024): @iGwkang The OS kills the foreground task, not that we want to terminate it 😅. When you put your application in the background, the OS will start scheduling when the background task can run. > Because most other apps can continue to run in the background, but immich can't. This is not true. Immich can run in the background when the OS allows it to. Can you provide an example of other apps?
Author
Owner

@iGwkang commented on GitHub (Sep 5, 2024):

@alextran1502 Some cloud storage applications can back up in the background, such as OneDrive, Dropbox, https://www.alipan.com and https://pan.baidu.com
They can switch the app to the background while backing up, and the backup will not be interrupted.

@iGwkang commented on GitHub (Sep 5, 2024): @alextran1502 Some cloud storage applications can back up in the background, such as [OneDrive](https://onedrive.live.com/), [Dropbox](https://www.dropbox.com/), https://www.alipan.com and https://pan.baidu.com They can switch the app to the background while backing up, and the backup will not be interrupted.
Author
Owner

@iGwkang commented on GitHub (Sep 5, 2024):

As I understand it, after the application switches to the background, you only need to keep the backup background service alive to solve this problem. This should be easy to do on Android.

@iGwkang commented on GitHub (Sep 5, 2024): As I understand it, after the application switches to the background, you only need to keep the backup background service alive to solve this problem. This should be easy to do on Android.
Author
Owner

@iGwkang commented on GitHub (Sep 7, 2024):

@alextran1502 @bo0tzz Hi, Will this issue be addressed?

@iGwkang commented on GitHub (Sep 7, 2024): @alextran1502 @bo0tzz Hi, Will this issue be addressed?
Author
Owner

@iGwkang commented on GitHub (Sep 9, 2024):

Will this problem be solved? If it can't be solved, please reply, thank you.

@iGwkang commented on GitHub (Sep 9, 2024): Will this problem be solved? If it can't be solved, please reply, thank you.
Author
Owner

@alextran1502 commented on GitHub (Sep 9, 2024):

I don't see there will be additional work forcing the job to continue when moving from foreground to background in the near future. As the bottle neck is how often the OS allow the background task to be executed, which is not under our control

@alextran1502 commented on GitHub (Sep 9, 2024): I don't see there will be additional work forcing the job to continue when moving from foreground to background in the near future. As the bottle neck is how often the OS allow the background task to be executed, which is not under our control
Author
Owner

@iGwkang commented on GitHub (Sep 9, 2024):

Thank you for your reply. I no longer have any expectations.

@iGwkang commented on GitHub (Sep 9, 2024): Thank you for your reply. I no longer have any expectations.
Author
Owner

@alextran1502 commented on GitHub (Sep 9, 2024):

Also, on Android, background backup often works better. Once you set the battery optimization to "Unrestricted", the background task will kick off as soon as a new photo is taken.

The challenging actor is iOS

@alextran1502 commented on GitHub (Sep 9, 2024): Also, on Android, background backup often works better. Once you set the battery optimization to "Unrestricted", the background task will kick off as soon as a new photo is taken. The challenging actor is iOS
Author
Owner

@alextran1502 commented on GitHub (Sep 9, 2024):

Thank you for your reply. I no longer have any expectations.

No problem, weekend just coming to an end here 😄

@alextran1502 commented on GitHub (Sep 9, 2024): > Thank you for your reply. I no longer have any expectations. No problem, weekend just coming to an end here 😄
Author
Owner

@iGwkang commented on GitHub (Sep 9, 2024):

Yes, immich worked very well when taking new photos, but it was too difficult for me to accept that the first backup required the app in the foreground.

@iGwkang commented on GitHub (Sep 9, 2024): Yes, immich worked very well when taking new photos, but it was too difficult for me to accept that the first backup required the app in the foreground.
Author
Owner

@alextran1502 commented on GitHub (Sep 9, 2024):

I think besides the app like native Photos app which might have access to unrestricted background time, there might not be any app that can realistically move hundred of gigabytes alone in the background in a timely manner.

Even with GPhotos on the iPhone, you will have to let it run for days in background mode alone to get your gallery up to Google

If you have the urge to get this resolve, we are open for contribution

@alextran1502 commented on GitHub (Sep 9, 2024): I think besides the app like native Photos app which might have access to unrestricted background time, there might not be any app that can realistically move hundred of gigabytes alone in the background in a timely manner. Even with GPhotos on the iPhone, you will have to let it run for days in background mode alone to get your gallery up to Google If you have the urge to get this resolve, we are open for contribution
Author
Owner

@iGwkang commented on GitHub (Sep 9, 2024):

https://github.com/immich-app/immich/issues/12341#issuecomment-2332113088
I have tested on Android that these applications can be backed up normally in the background. But I didn't test it on iOS.I don't have expectations for iOS either, because the iOS system will let background applications enter Doze mode. But what I can be sure of is that Android can definitely backup applications in the background.

@iGwkang commented on GitHub (Sep 9, 2024): https://github.com/immich-app/immich/issues/12341#issuecomment-2332113088 I have tested on Android that these applications can be backed up normally in the background. But I didn't test it on iOS.I don't have expectations for iOS either, because the iOS system will let background applications enter Doze mode. But what I can be sure of is that Android can definitely backup applications in the background.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: immich-app/immich#4229