For context: I need to be able to reliably update the timestamp on some sqlite DB files which get intermittent updates on an ext4 filesystem.
Can using the touch
command (to update the last modification time) fail when the database is being written to, or even worse, cause data loss?
You can indeed
touch
an open file without corrupting its content, as the filesystem will serialize updates to inode metadata.If this is safe from an application point of view is another matter entirely, but it should be safe simple because even reading a file can update its metadata (ie: when the last read is older than one day or when not using
noatime
,relatime
orlazytime
).That said, if SQLite uses
mtime
for some internal bookkeeping it can be confused by your metadata changes. This is especially true if using touch for setting a past timestamp, which is generally a bad idea.