3 # This script makes a rotating backup of the very
4 # important database files $chroot/etc/passwd and
5 # $chroot/etc/group and $chroot/etc/sshkeys.
6 # Backup files are rotated dropping .9.$ext and
7 # renaming the others to the next higher number
8 # and then finally making a copy of the original
9 # to a .1 (not compressed for passwd and group).
11 # Running this regularly from a cron entry is
12 # highly recommended. It may be run manually
13 # from the $basedir/toolbox directory any time
14 # after make install has been run to create an
17 # Backups retain the modification date of the file
18 # they are backing up at the time the backup was
19 # made. If restoration is required this can be
20 # used to determine the time period from which data
21 # would be lost if the backup were to be used.
27 # rotate_file basename suffix
29 [ -f "$1.8.$2" ] && mv -f "$1.8.$2" "$1.9.$2"
30 [ -f "$1.7.$2" ] && mv -f "$1.7.$2" "$1.8.$2"
31 [ -f "$1.6.$2" ] && mv -f "$1.6.$2" "$1.7.$2"
32 [ -f "$1.5.$2" ] && mv -f "$1.5.$2" "$1.6.$2"
33 [ -f "$1.4.$2" ] && mv -f "$1.4.$2" "$1.5.$2"
34 [ -f "$1.3.$2" ] && mv -f "$1.3.$2" "$1.4.$2"
35 [ -f "$1.2.$2" ] && mv -f "$1.2.$2" "$1.3.$2"
39 # backup_file basename
41 rotate_file2_9
"$1" gz
42 if [ -f "$1.1" ]; then
44 gzip -n9 < "$1.1" > "$1.2.gz" && \
45 touch -r "$1.1" "$1.2.gz" && \
49 cp -pf "$1" "$1.1" && \
58 rotate_file2_9
"$1" tar.gz
59 [ -f "$1.1.tar.gz" ] && mv -f "$1.1.tar.gz" "$1.2.tar.gz"
62 base
="$(basename "$1")"
63 rm -f "$base.1.tar.gz"
64 tar -c -f - $base |
gzip -n9 > "$base.1.tar.gz"
65 chmod a-w
"$base.1.tar.gz"
71 if [ -z "$cfg_chroot" ] ||
[ "$cfg_chroot" = "/" ]; then
72 echo 'Config.pm chroot setting is invalid' >&2
76 backup_file
"$cfg_chroot/etc/passwd"
77 backup_file
"$cfg_chroot/etc/group"
78 backup_dir
"$cfg_chroot/etc/sshkeys"