8

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?

Hart Simha
  • 1,183
  • 7
  • 7

1 Answers1

11

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 or lazytime).

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.

shodanshok
  • 44,038
  • 6
  • 98
  • 162