I had a Syncthing accident that caused all Obsidian vault files to deleted. This happened because I setup a git repo for the vault today, then attempted to rename all folders to be lowercase. Since macOS and Android are both case insensitive filesystems, git mv Daily daily
doesn’t work as it attempts to move the folder to being a subfolder of itself. However, rename does work in macOS Finder and in Obsidian’s File Explorer.
In the process of figuring out how to do this, I ended up causing Syncthing to get confused and delete all files (I guess it synced new files at daily/*
first and then attempted to delete old files from Daily/*
). Fortunately, this was undoable using git restore .
, but I did have to stop Syncthing on other devices to stop the deletes from propagating in circles, and had to do a git restore
separately on both Android devices before restarting Syncthing on them. (One of my Syncthing devices is a NAS running a case-sensitive Btrfs filesystem, so I suspect it to be the source of these add-first-and-then-delete changes.)
Next I found the timestamps on all files were now reset to the present moment. Both creation time and modification time. That wasn’t nice, so I looked in Time Machine backups, confirmed the original timestamps were preserved there, and restored from all folders. I don’t want to overwrite the current versions though, I just want to fix timestamps. Ended up with this little shell script to compare two folders, read ctime and mtime from all files and folders in the first folder (vault-from-backup
) and set them on the second (vault
) if the same file exists there:
#!/bin/bash
find vault-from-backup | while read name; do
ctime=$(GetFileInfo -d "$name")
mtime=$(GetFileInfo -m "$name")
repl="vault/${name#vault-from-backup/}"
if [ -e "$repl" ]; then
SetFile -d "$ctime" -m "$mtime" "$repl"
fi
done