The motivation of tmpfs-sync is to reduce the number of write operations to your hard disk to a minimum in order to increase the potential lifetime of SSD drives.
tmpfs-sync operates on a per-directory basis. Before a directory is accessed (e.g. during boot), the following actions are performed:
- A copy is created on a tmpfs-mount (e.g. /dev/shm).
- The original directory is renamed.
- A link to the copy is put in place of the original directory.
When the directory is not accessed anymore (e.g. at shutdown), the content of the tmpfs-copy is moved back to the original directory by:
- Copying the content of the tmpfs-copy to the renamed original directory (sync).
- Deleting the link to the tmpfs-copy.
- Renaming the on-disk directory to its original name.
- Deteting the tmpfs-copy.
To keep the risk of data-loss due to OS-crashes minimal the sync step above can (should?) be performed regularly.
At the moment, tmpfs-sync is implemented as a Zsh script which calls lsof to check if releasing is safe and rsync to synchronize.
For integration with systemd, the script is accompanied by a number of .service and .timer files.
Command line interface:
usage: tmpfs-sync COMMAND DIR possible COMMANDs: init Initialize tmpfs copy sync Synchronize tmpfs content to on-disk copy release Release directory sync (does not sync!) sync-release Synchronize and release directory sync status Print status of DIR recover Fix DIR after a crash
Other options are controlled via environment variables:
- TMPFSDIR
- The directory where the tmpfs copies are created. Defaults to /dev/shm/tmpfs-sync.d/.
- TMPFSSYNC_LOGLEVEL
- The verbosity of the script (1-5). Lower means more verbose. Defaults to 3.
The systemd service defined in tmpfs-sync.service requires a config file at /etc/tmpfs-sync.conf which must contain one directory per line (no comments or such allowed). A systemd timer to regularly (every 2 hours) synchronize is defined in tmpfs-sync.sync.timer and tmpfs-sync.sync.service.
Copy tmpfs-sync somewhere in your $PATH. For integration with systemd, it must be installed in /usr/local/bin/ and the *.service and *.timer files must be copied to /etc/systemd/system/ (at least with Debian) and enable the services and timer via systemd enable tmpfs-sync.service tmpfs-sync.sync.service tmpfs-sync.sync.timer.