Thanks to visit codestin.com
Credit goes to github.com

Skip to content

eikevons/tmpfs-syncer

Repository files navigation

tmpfs-sync: Keep write operations on disks minimal

Introduction

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:

  1. A copy is created on a tmpfs-mount (e.g. /dev/shm).
  2. The original directory is renamed.
  3. 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:

  1. Copying the content of the tmpfs-copy to the renamed original directory (sync).
  2. Deleting the link to the tmpfs-copy.
  3. Renaming the on-disk directory to its original name.
  4. 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.

Requirements

Zsh, lsof, rsync

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.

Usage

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.

Installation

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.

About

Keep write operations on disks minimal

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages