#!/bin/sh # # $Id: etcbackup.sh 216 2010-11-06 16:38:30Z rick $ # Poor mans configuration backup. Only save the new backup if configuration # content changes # # Rick van der Zwet TAG=`date "+%Y%m%d"` BACKUPROOT=/usr/local/backup/config TARGET=$BACKUPROOT/etc-$TAG.tar # Check for last backup file mkdir -p $BACKUPROOT LAST=`ls -t1 /usr/local/backup/config/etc-*.tar | head -1` if [ "$LAST" = "$TARGET" ]; then echo "# Error file '$TARGET' does already exists" 1>&2 exit 1 fi # Create new backup file tar -C / -cf $TARGET etc usr/local/etc 2>&1 # If old file this exists, only keep new files if changes exists if [ -n "$LAST" ]; then PREV_MD5=`md5 -q $LAST` NEW_MD5=`md5 -q $TARGET` if [ "$PREV_MD5" = "$NEW_MD5" ]; then rm $TARGET fi fi