#! /bin/sh ### BEGIN INIT INFO # Provides: logbackup # Required-Start: $local_fs $remote_fs # Required-Stop: $local_fs $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 6 # Short-Description: Back-up and rotation of log files # Description: This script runs a last backup & rotation of the log files # before halting the system. The system logs would otherwise # be lost since they reside in a tmpfs partition. ### END INIT INFO # Author: François Févotte DESC="logbackup" FRAGDIR="/etc/logbackup.d" # Load the VERBOSE setting and other rcS variables . /lib/init/vars.sh # Define LSB log_* functions. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. . /lib/lsb/init-functions [ -r /etc/logbackup.conf ] && . /etc/logbackup.conf # Retrieve backed-up logs do_retrieve() { for FRAGMENT in $FRAGDIR/*; do [ -x $FRAGMENT ] && $FRAGMENT retrieve done return 0 } # Rotation and backup of the logs do_backup() { if [ "$LOGBACKUP_INCLUDED" != "" ]; then echo $LOGBACKUP_INCLUDED > $LOGBACKUP_INCLUDED if [ "$LOGBACKUP_OMITTED" != "" ]; then echo $LOGBACKUP_OMITTED >> $LOGBACKUP_INCLUDED rm -f $LOGBACKUP_OMITTED fi fi for FRAGMENT in $FRAGDIR/*; do [ -x $FRAGMENT ] && $FRAGMENT backup done if [ "$LOGBACKUP_INCLUDED" != "" -a "$LOGBACKUP_OMITTED" != "" ]; then echo "# This is the list of all files in /var/log that were not" >> $LOGBACKUP_OMITTED echo "# handled by logbackup. " >> $LOGBACKUP_OMITTED echo "# You shoud pay attention to these files, as they may " >> $LOGBACKUP_OMITTED echo "# grow to very large sizes and fill your entire /var/log " >> $LOGBACKUP_OMITTED echo "# partition. If you do not want to keep these log files, " >> $LOGBACKUP_OMITTED echo "# you can add them to the list of files cleaned by " >> $LOGBACKUP_OMITTED echo "# logbackup in /etc/logbackup.d/clean, so that they will " >> $LOGBACKUP_OMITTED echo "# be removed once a day. " >> $LOGBACKUP_OMITTED echo " " >> $LOGBACKUP_OMITTED find /var/log -not -type d \ | grep -v -f $LOGBACKUP_INCLUDED \ >> $LOGBACKUP_OMITTED fi return 0 } case "$1" in start) [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" logger -i -t "logbackup" "Retrieve backed-up logs at system startup" do_retrieve [ "$VERBOSE" != no ] && log_end_msg 0 ;; stop) [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" logger -i -t "logbackup" "Back-up the logs before halting" do_backup [ "$VERBOSE" != no ] && log_end_msg 0 ;; restart|reload|force-reload) log_daemon_msg "Restarting $DESC" "$NAME" logger -i -t "logbackup" "Back-up the logs at the user's request" do_backup log_end_msg 0 ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 exit 3 ;; esac :