Skip to content

Instantly share code, notes, and snippets.

@roycewilliams
Created April 12, 2018 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roycewilliams/64531cf5470d8ccf6e616f1655cc8e45 to your computer and use it in GitHub Desktop.
Save roycewilliams/64531cf5470d8ccf6e616f1655cc8e45 to your computer and use it in GitHub Desktop.
ntpmemlog.txt
# grep ntpstats /etc/fstab
tmpfs /var/log/ntpstats tmpfs defaults,noatime,nodiratime,nosuid,mode=0755,size=200m 0 0
# cat /etc/init.d/ntpmemlog
#!/bin/sh
### BEGIN INIT INFO
# Provides: ntpmemlog
# Required-Start: $local_fs $time
# X-Stop-After: $time
# Required-Start: $local_fs $time
# Required-Stop: $local_fs
# Default-Start: S
# Default-Stop: 0 1 6
# Short-Description: Restore to and save ntpstats from tmpfs filesystem
# Description: Restore to and save ntpstats from tmpfs filesystem
### END INIT INFO
# /etc/init.d/ntpmemlog
# Credit: https://steinar.bang.priv.no/2016/07/03/logging-to-persistent-tmpfs-on-raspbian-jessie/
#
case "$1" in
start)
echo "Syncing ntpstats from storage to tmpfs"
rsync -avrq /var/backups/ntpstats/* /var/log/ntpstats/
echo "[`date +"%Y-%m-%d %H:%M"`] tmpfs synced from storage (start)" >> /var/log/ramdisk_sync.log
;;
sync)
echo "Syncing ntpstats from tmpfs to storage"
echo "[`date +"%Y-%m-%d %H:%M"`] ntpstats synced to storage (sync)" >> /var/log/ramdisk_sync.log
rsync -avryq --delete --force /var/log/ntpstats/* /var/backups/ntpstats/
;;
stop)
echo "Syncing ntpstats from tmpfs to storage"
echo "[`date +"%Y-%m-%d %H:%M"`] ntpstats synced to storage (stop)" >> /var/log/ramdisk_sync.log
rsync -avrq --delete --force /var/log/ntpstats/* /var/backups/ntpstats/
;;
status)
echo "Comparing ntpstats from tmpfs to storage"
echo
rsync -avr --dry-run --force /var/log/ntpstats/* /var/backups/ntpstats/
;;
*)
echo "Usage: /etc/init.d/ntpmemlog {start|stop|status}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment