#!/bin/sh echo -n "Saving configuration... " if [ ! -f /etc/diskless ] then echo "No flash setup detected." exit 1 fi find_newer_files() { [ -d "${1}" ] || return 1 find "${1}" -type f -not -regex '.*/tmp/*.' -newer /etc/diskless -print } archive() { [ -d "${1}" ] || return 1 find_newer_files "${1}" | cpio -o | gzip -9 > "/conf/default/${1}.cpio.gz" } # Mount /conf read-write, and remount if it already is. if [ $(grep -c /conf /etc/fstab) -gt 0 ] then mount -w /conf if [ $? -ne 1 ] then umount /conf mount -w /conf _was_mounted=true fi fi # Unlimited history method: (make sure you have provisions for removing the old backups, or this can get HUGE! dest="$(date -r "$(stat -f '%c' "/conf/default")" "+%Y-%m-%dT%H-%M-%S")" mv /conf/default "/conf/backup/${dest}" mkdir /conf/default cd / # Copy changed config files to /conf/default (anything younger than /etc/diskless) #find etc var -type f -not -regex '.*/tmp/.*' -newer /etc/diskless -print0 | cpio -p /conf/default/ # This can be changed to allow compressed configuration here as well: archive etc archive var # Umount /conf afterwards, if it wasn't mounted if [ -z "${_was_mounted}" -a "$(mount |grep -c "/conf")" -gt 0 ] then umount /conf fi echo "Done!"