I’ve made the following backup script for my immich stack to be automatically run every day

# Load variables from the .env file
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
set -a
source "$SCRIPT_DIR/../.env"
set +a

# Create a dump of the database and back it up
docker exec -it immich_db pg_dumpall -c -U immich > immich/latest_db_dump.sql
rustic -r $BUCKET_NAME/immich backup immich/latest_db_dump.sql --password=$REPO_PWD

# Backup the library, uploads and profile folders from the upload volume
rustic -r $BUCKET_NAME/immich backup immich/uploads_v/library --password=$REPO_PWD
rustic -r $BUCKET_NAME/immich backup immich/uploads_v/upload --password=$REPO_PWD
rustic -r $BUCKET_NAME/immich backup immich/uploads_v/profile --password=$REPO_PWD

# Apply forget policy
rustic -r $BUCKET_NAME/immich forget $RUSTIC_FORGET_POLICY --password=$REPO_PWD

and when I test it everything works properly, and the created sql dump file is complete and properly backed up.

However, when the execution is triggered automatically by a cronjob (as specified in this crontab line)

"30 3 * * *    root    /home/admin/WinguRepo/scripts/docker_backupper.sh"

(the line is taken from the nixos configuration file, that’s why it also contains the user executing the operation)

it seems something breaks in the dumping process, because the script completes successfully but the sql dump file is an empty file (as can be noticed in the following output of rustic -r myrepo snapshots

snapshots for (host [wingu-box], label [], paths [immich/latest_db_dump.sql])
| ID       | Time                | Host      | Label | Tags | Paths                     | Files | Dirs |      Size |
|----------|---------------------|-----------|-------|------|---------------------------|-------|------|-----------|
| 10a32a83 | 2025-01-06 20:56:48 | wingu-box |       |      | immich/latest_db_dump.sql |     1 |    2 | 264.6 MiB |
| 1174bc2e | 2025-01-07 12:50:36 | wingu-box |       |      | immich/latest_db_dump.sql |     1 |    2 | 264.6 MiB |
| 00977334 | 2025-01-08 03:31:24 | wingu-box |       |      | immich/latest_db_dump.sql |     1 |    2 |       0 B |
| 513fffa1 | 2025-01-10 03:31:25 | wingu-box |       |      | immich/latest_db_dump.sql |     1 |    2 |       0 B |
4 snapshot(s)

(the first two snapshots were manually triggered by me executing the script, the latter two instead are triggered automatically by the cronjob)

Any idea about what is causing this behavior?

  • tuxiqae@lemmy.dbzer0.com
    link
    fedilink
    English
    arrow-up
    2
    ·
    edit-2
    1 hour ago

    Add set -x and dump the output (both stdout, stderr) into a logfile

    Usually issues with crontab are related to variables ( PATH) as well, so you might want to consider verifying that.

  • 486@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    53 minutes ago

    The script appears to be missing the #! line. Without that, it is unclear which interpreter should be used for executing the script.

  • farcaller@fstab.sh
    link
    fedilink
    English
    arrow-up
    5
    ·
    3 hours ago

    You don’t need -it because you don’t run an interactive session in docker. It might be failing because you ask for a pseudoterminal in an environment where it doesn’t make sense.