]> CyberLeo.Net >> Repos - CDN/Mosi.git/blob - patch/sbin_saveconfig-script.patch
script/gentree: add overlay support
[CDN/Mosi.git] / patch / sbin_saveconfig-script.patch
1 --- /dev/null   2010-01-30 08:55:01.000000000 +0000
2 +++ sbin/saveconfig     2010-01-24 11:02:05.000000000 +0000
3 @@ -0,0 +1,53 @@
4 +#!/bin/sh
5 +
6 +echo -n "Saving configuration... "
7 +
8 +if [ ! -f /etc/diskless ]
9 +then
10 +    echo "No flash setup detected."
11 +    exit 1
12 +fi
13 +
14 +find_newer_files() {
15 +  [ -d "${1}" ] || return 1
16 +  find "${1}" -type f -not -regex '.*/tmp/*.' -newer /etc/diskless -print
17 +}
18 +
19 +archive() {
20 +  [ -d "${1}" ] || return 1
21 +  find_newer_files "${1}" | cpio -o | gzip -9 > "/conf/default/${1}.cpio.gz"
22 +}
23 +
24 +# Mount /conf read-write, and remount if it already is.
25 +if [ $(grep -c /conf /etc/fstab) -gt 0 ]
26 +then
27 +        mount -w /conf
28 +        if [ $? -ne 1 ]
29 +        then
30 +                umount /conf
31 +                mount -w /conf
32 +               _was_mounted=true
33 +        fi
34 +fi
35 +
36 +
37 +# Unlimited history method: (make sure you have provisions for removing the old backups, or this can get HUGE!
38 +dest="$(date -r "$(stat -f '%c' "/conf/default")" "+%Y-%m-%dT%H-%M-%S")"
39 +mv /conf/default "/conf/backup/${dest}"
40 +
41 +mkdir /conf/default
42 +
43 +cd /
44 +# Copy changed config files to /conf/default (anything younger than /etc/diskless)
45 +#find etc var -type f -not -regex '.*/tmp/.*' -newer /etc/diskless -print0 | cpio -p /conf/default/
46 +# This can be changed to allow compressed configuration here as well:
47 +archive etc
48 +archive var
49 +
50 +# Umount /conf afterwards, if it wasn't mounted
51 +if [ -z "${_was_mounted}" -a "$(mount |grep -c "/conf")" -gt 0 ]
52 +then
53 +        umount /conf
54 +fi
55 +
56 +echo "Done!"