User Tools

Site Tools


software:misc:ramdisk-log

Software: RAM Disk Based Logs On Flash Device

The biggest problem with flash based devices is that the life of the device is limited by it's write cycles. This init script (developed on debian, no idea if it will work on other distros) handles extracting a log tarball at boot from the flash device, and at shutdown backs up the log files to the same tarball.

When used with a RAM Disk on /var/log, this can save a bit of write cycles on your device.

Command Line Options:

  • start - extracts the log files, used at boot
  • stop - backs up the log files, used at shutdown
  • sync - backs up the log files right away (useful in a cronjob)
#!/bin/sh
### BEGIN INIT INFO
# Provides:          sosdg-ramdisk-log
# Required-Start:    $local_fs
# Required-Stop:     $local_fs
# X-Start-Before:    rsyslog asterisk
# X-Stop-After:      rsyslog asterisk
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Handle ramdisk /var/log
# Description:       Handle ramdisk fun at boot and shutdown
### END INIT INFO

PATH=/bin:/sbin:/usr/bin:/usr/sbin
TAR=/bin/tar
LOGDIR=/var/log
TMPDIR=/tmp
LOGTARBALL=/root/log.tar.gz
. /lib/lsb/init-functions

case "${1:-}" in
  start)
        log_begin_msg "Extracting $LOGTARBALL to $LOGDIR..."
        cd $LOGDIR
        $TAR zxf $LOGTARBALL
        log_end_msg $?
  ;;
  stop)
        log_begin_msg "Backing up logs from $LOGDIR to $LOGTARBALL..."
        cd $LOGDIR
        $TAR zcf $LOGTARBALL *
        log_end_msg $?
  ;;
  sync)
        cd $LOGDIR
        $TAR zcf $LOGTARBALL *
  ;;
  *)
        log_success_msg "Usage: /etc/init.d/sosdg-ramdisk-log {start|stop|sync}"
        exit 1
esac
exit 0
software/misc/ramdisk-log.txt · Last modified: 2010/06/29 09:35 by brielle