Recovering a Self-Hosted Photo Library from a Temporary Directory After Index Loss

    When a self-hosted photo library loses its database records, mount points, or scan state, the web UI may show an empty library even though the original files remain on disk. This guide walks through distinguishing index loss from actual file loss, exposing a temporary directory to containers via mounts, running a recursive bulk import, validating the results, and rolling back safely—so you can restore your library without re-uploading photos one folder at a time.

    When a self-hosted photo album runs in “external folder as media library” mode, the database stores only paths, hashes, and album relations, while the actual images remain on disk. If the library records are lost, a mount point changes, or a scan job is interrupted, the UI may appear completely blank or report large numbers of “missing files”—yet the subfolders and original photos in the temporary directory are usually still intact. The key to recovery is not uploading photos one by one through the web UI, but making the application process able to read that directory tree, then triggering a recursive scan and bulk import. This article walks through the steps in a practical order, along with the associated risk controls.

    First, Determine Whether You Lost the Index or the Files

    Before touching any configuration, distinguish between two types of failure. The first is metadata loss: the database is reachable and the storage volume exists, but the asset table, album associations, or thumbnail jobs are empty. The second is file inaccessibility: the path was moved, permissions changed, or the container cannot see the host directory. If you only repair the database without restoring a readable path, the scan will return nothing; if you only copy the files without rebuilding the index, the photos still won’t appear in the UI.

    Start with three read-only checks: verify the file count and approximate total size of the temporary directory; spot-check several subfolders to confirm they still contain common image or video files; confirm the database service is healthy and the cache service is reachable. If the files are still there, the remaining work is “re-expose the path + bulk import + verify the results.” If the files were physically deleted, no scan can conjure them back—you must first restore them from backup before any import.

    Mount the Temporary Directory Into the App Instead of Copying It to the System Disk

    A process inside a container can only see volumes declared in the orchestration file. If the temporary directory exists only on the host, neither the web UI’s upload function nor the server-side scanner can access it. The correct approach is to mount the host’s temporary root directory—read-only or read-write—into a dedicated path inside the container, such as an import directory, and make sure the album service and the background processing service see the same media root path. The background worker handles preview generation, metadata extraction, and queue writes; if only the frontend service can see the files, those jobs will fail or repeatedly report “path not found.”

    Before modifying the orchestration, copy the current file and name it with a date so you can roll back entirely if the mount is wrong. The media root directory should continue to be specified via a single environment variable, avoiding hand-written absolute paths that drift apart in different places. When adding a mount, watch three things: the host path must actually exist, and don’t expose an entire system directory into the container; the target path inside the container must not overwrite the app’s existing upload or configuration directories; and database credentials and cache addresses should keep coming from the environment file—never write secrets into the orchestration file itself or commit them to version control.

    A sample structure (paths and service names are generic examples—replace them with your actual deployment):

    services:
    media-server:
    volumes:

    1. - ${MEDIA_ROOT}:/data
    2. - /srv/photo-temp:/import-temp:ro

    media-worker:
    volumes:

    1. - ${MEDIA_ROOT}:/data
    2. - /srv/photo-temp:/import-temp:ro

    A read-only mount suits the “scan first to confirm, then decide whether to migrate into the formal library” approach. If the import process must move files into the formal upload directory, switch to read-write, and make sure the directory contains only the photos awaiting recovery—otherwise unrelated data may get scanned into the album.

    Recursive Scanning and Bulk Import Should Cover the Whole Tree at Once

    Temporary directories often contain multiple levels of subfolders organized by year, month, or event. Uploading folder by folder is slow and error-prone. An album service with recursive scanning capability will perform a deep traversal of the specified root path: identifying images and videos, computing content hashes, skipping unsupported extensions, writing importable objects to the database, and dispatching background jobs. Operationally, pick the container’s import root path as the external library or import source, enable subdirectory inclusion, and don’t create a separate task for each subfolder.

    Before a full bulk import, do a small dry run: copy a few dozen files into a separate test directory, mount it on its own, and confirm that photos appear on the timeline, album counts increase, and previews generate. Only then run the full scan against the real temporary directory. While the full scan is running, don’t change mounts, don’t restart the processing service, and don’t move files on the host that are being read—otherwise some records will point to stale paths.

    If your platform distinguishes between an “external library” and an “upload library” as two storage semantics, decide on your recovery target first. The external library mode typically leaves files in place and only builds an index, suiting scenarios where files must stay in their original directory. The upload library mode copies or moves files into a location managed by the media root, suiting scenarios where the temporary disk is about to be retired and you want to rely on a single storage location going forward. Don’t mix the two modes on the same batch of files in one job, or you’ll end up with duplicate assets.

    Startup, Observation, and Acceptance After the Orchestration Change

    After saving the orchestration file, recreate the affected containers so the new volumes take effect. Merely restarting old containers sometimes doesn’t refresh mount definitions—redeploy through your orchestration tool instead. After startup, check the application logs and the processing service logs for phrases like database connection failures, no permission to access the import path, disk read-only, or queue backlog. Permission issues are especially common: when the in-container user doesn’t match the host directory’s owner, the scan silently skips files. You can temporarily make the import directory readable by the container user and tighten permissions once recovery is complete—don’t take the shortcut of making the whole media tree writable by everyone.

    Acceptance shouldn’t stop at “the task reports success.” Check three things: whether the number of imported assets is in the same ballpark as the count of recognizable media files in the temporary directory (slightly fewer is fine, due to duplicate hashes or unsupported formats); whether photos from subfolders at different levels open correctly, with previews and originals loading; and whether capture timestamps come from file metadata rather than the import time. If a large batch of photos is clustered on the import date, metadata extraction likely failed—re-run the extraction jobs while the files are still in place rather than copying the files again.

    Deduplication should rely on content hashes, not file names. If the same photo previously existed under a different file name, a second scan should recognize it as an existing asset. If the system lacks deduplication and you performed a copy-based import, you’ll get duplicate records. Once duplicates are found, merge or delete the extras through the UI or the admin interface—never delete database rows directly, which leaves orphaned preview files and album relations behind.

    Rollback on Failure and How to Avoid Losing the Library Again

    If a new mount prevents the service from starting, restore from the backed-up orchestration file and redeploy—don’t keep patching a broken draft. If a scan has written records pointing to wrong paths, stop the import job first, then remove that external library or import batch through the platform’s library management features. After confirming the formal media root wasn’t accidentally deleted, fix the path and rescan. Deletions should target only indexes or the current import batch—never recursively delete the formal upload directory.

    Long-term protection is straightforward. Back up the media root and the database separately, with a backup interval shorter than the data-loss window you can tolerate. Put orchestration files and environment variable templates under version control, and manage secrets with a dedicated secret manager rather than scattering them in plain text. When changing the path of an external folder library, complete a full scan and verification on the new path before retiring the old one. Schedule large directory imports during off-peak hours, and reserve disk space for previews and transcoding—running out of space causes half-finished jobs that show up in the UI as “some albums missing.” At minimum, set up alerts for database unavailability, disk usage, and import queue backlog, so silent failures don’t go unnoticed for weeks.

    Object storage, container platforms, and logging services can each handle photo persistence, runtime environments, and failure forensics—but none of them solves the configuration problem of “the container can’t see the host’s temporary directory.” When recovering a photo library, completing four steps—“files are intact, the path is visible, one recursive import, verification by counts and sampling”—is far more reliable than repeatedly clicking upload on individual folders, and far less likely to break an otherwise healthy media root in a moment of panic.