Restic is claiming the temp file for packing doesn't exist when it has permission and the directory exists

edit: I was so used to seeing an “inaccecible” error message that I didn’t catch the tail end of this message until it was posted on a forum. (Stupid tiny screen!) However, a thread is still needed since there is still an error message that shouldn’t be so I fixed this post accordingly.

I wrote a backup script for my desktop which, in theory work on my tablet under Termux. However, reality is having none of it.

Fatal: unable to save snapshot: fs.TempFile: open /data/data/com.termux/files/usr/tmp/restic-tmp/restic-temp-pack-4233175164: no such file or directory

For my main script, that is always thrown. I’ve tried constructing a minimal working example, but the fact of the matter is, sometimes it works and sometimes it doesn’t. I’m not sure what the source of the problem is since the directory does exist and I can’t know the exact file name for the pack ahead of time.

#!/data/data/com.termux/files/usr/bin/env -S clojure -M

(require '[clojure.java.shell :refer [sh]])

(def env {"RESTIC_REPOSITORY" "test/local"
          "RESTIC_PASSWORD" "1"
          "RESTIC_CACHE_DIR" "/data/data/com.termux/files/usr/tmp/restic-cache"
          "TMPDIR" "/data/data/com.termux/files/usr/tmp/restic-tmp"})

(println (sh "restic" "backup" "./src" :env env))

It written in Clojure, but it is very simple and intended to run on it’s own. I did this to isolate it from the build environment. (The ~/.clojure/profile.edn file is basically empty in that it has no deps specified.)

There’s no OS specific code, so this should work just as well on my tablet as my desktop.

$ restic version
restic 0.14.0 compiled with go1.19 on android/arm64

It’s probably worth mentioning that a similiar Bash script does not have this issue, so presumably this has at least something to do with the JVM. However, this is the only error message I’m getting, so this is where I’m starting.

Does the tmpdir exist before and after running restic? Judging from the code, pretty much the only way to cause that error is if the tmpdir does not exist.

No, however a similiar script written in Bash (below) also doesn’t and it works fine. What’s more, if I specify ~/.restic/tmp (with ~ expanded), this so far works fine. Of course, given that this is an intermittent problem, it could just be luck.

#!/data/data/com.termux/files/usr/bin/bash

export RESTIC_REPOSITORY="test/local"
export RESTIC_PASSWORD="1"
export RESTIC_COMPRESSION="NONE"
export RESTIC_CACHE_DIR="/data/data/com.termux/files/usr/tmp/restic-cache"

restic backup "./src"

To be clear, by the way, though the error comes from Restic, I don’t think it’s a Restic bug. I just think it’s a weird interaction between Restic and the JVM on… Android? I’m not sure what you would call the environment for Termux. Still, I figure this is where to start.

Edit: Err, actually, that script works but doesn’t even specify a TMPDIR. I just noticed that. For sure, the Clojure script fails without an explicit TMPDIR. Also, it specifies compression. I was trying all kinds of combinations of things to try breaking one and fixing the other. They matched up any number of times.

edit2: Apparently I did not test with export TMPDIR=.... The Bash script also fails with the same error message. mkdiring the directory does indeed fix this.

Sorry for wasting your time Michael.

edit3: For anyone wondering about this further, it seems as though when executed by the JVM (and possiby other VM-based langauges?) Restic tries to use an inaccessible directory for it’s temporary files. To work around this you need to point it at another TMPDIR. However, unlike specifying the the RESTIC_CACHE_DIR, this is not enough to create the directory: it must be made manually.