this post was submitted on 10 Jan 2025
7 points (100.0% liked)

Selfhosted

40974 readers
579 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

Rules:

  1. Be civil: we're here to support and learn from one another. Insults won't be tolerated. Flame wars are frowned upon.

  2. No spam posting.

  3. Posts have to be centered around self-hosting. There are other communities for discussing hardware or home computing. If it's not obvious why your post topic revolves around selfhosting, please include details to make it clear.

  4. Don't duplicate the full text of your blog or github here. Just post the link for folks to click.

  5. Submission headline should match the article title (don’t cherry-pick information from the title to fit your agenda).

  6. No trolling.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

founded 2 years ago
MODERATORS
 

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?

top 3 comments
sorted by: hot top controversial new old
[–] farcaller@fstab.sh 9 points 11 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.

[–] tuxiqae@lemmy.dbzer0.com 3 points 8 hours ago* (last edited 8 hours 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 1 points 8 hours ago

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