From d8f571596cb2a0b2904d13e6f190b2c35e33748a Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Mon, 24 Nov 2014 11:22:11 -0800 Subject: [PATCH] backup-db.sh: include sshkeys in the backups --- toolbox/backup-db.sh | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/toolbox/backup-db.sh b/toolbox/backup-db.sh index db6e209..93ba9f3 100755 --- a/toolbox/backup-db.sh +++ b/toolbox/backup-db.sh @@ -2,10 +2,11 @@ # This script makes a rotating backup of the very # important database files $chroot/etc/passwd and -# $chroot/etc/group. Backup files are rotated -# dropping .9.gz and renaming the others to the -# next higher number and then finally making a -# copy of the original to a .1 (not compressed). +# $chroot/etc/group and $chroot/etc/sshkeys. +# Backup files are rotated dropping .9.$ext and +# renaming the others to the next higher number +# and then finally making a copy of the original +# to a .1 (not compressed for passwd and group). # Running this regularly from a cron entry is # highly recommended. It may be run manually @@ -23,14 +24,21 @@ set -e . @basedir@/shlib.sh +# rotate_file basename suffix +rotate_file2_9() { + [ -f "$1.8.$2" ] && mv -f "$1.8.$2" "$1.9.$2" + [ -f "$1.7.$2" ] && mv -f "$1.7.$2" "$1.8.$2" + [ -f "$1.6.$2" ] && mv -f "$1.6.$2" "$1.7.$2" + [ -f "$1.5.$2" ] && mv -f "$1.5.$2" "$1.6.$2" + [ -f "$1.4.$2" ] && mv -f "$1.4.$2" "$1.5.$2" + [ -f "$1.3.$2" ] && mv -f "$1.3.$2" "$1.4.$2" + [ -f "$1.2.$2" ] && mv -f "$1.2.$2" "$1.3.$2" + return 0 +} + +# backup_file basename backup_file() { - [ -f "$1.8.gz" ] && mv -f "$1.8.gz" "$1.9.gz" - [ -f "$1.7.gz" ] && mv -f "$1.7.gz" "$1.8.gz" - [ -f "$1.6.gz" ] && mv -f "$1.6.gz" "$1.7.gz" - [ -f "$1.5.gz" ] && mv -f "$1.5.gz" "$1.6.gz" - [ -f "$1.4.gz" ] && mv -f "$1.4.gz" "$1.5.gz" - [ -f "$1.3.gz" ] && mv -f "$1.3.gz" "$1.4.gz" - [ -f "$1.2.gz" ] && mv -f "$1.2.gz" "$1.3.gz" + rotate_file2_9 "$1" gz if [ -f "$1.1" ]; then rm -f "$1.2.gz" gzip -n9 < "$1.1" > "$1.2.gz" && \ @@ -44,6 +52,21 @@ backup_file() { return 0 } +# badkup_dir basename +backup_dir() ( + set -e + rotate_file2_9 "$1" tar.gz + [ -f "$1.1.tar.gz" ] && mv -f "$1.1.tar.gz" "$1.2.tar.gz" + if [ -d "$1" ]; then + cd "$(dirname "$1")" + base="$(basename "$1")" + rm -f "$base.1.tar.gz" + tar -c -f - $base | gzip -n9 > "$base.1.tar.gz" + chmod a-w "$base.1.tar.gz" + fi + return 0 +) + # Be paranoid if [ -z "$cfg_chroot" ] || [ "$cfg_chroot" = "/" ]; then echo 'Config.pm chroot setting is invalid' >&2 @@ -52,5 +75,6 @@ fi backup_file "$cfg_chroot/etc/passwd" backup_file "$cfg_chroot/etc/group" +backup_dir "$cfg_chroot/etc/sshkeys" exit 0 -- 2.11.4.GIT