[debian-lan-devel] [SCM] Debian-LAN development and packaging branch, squeeze, updated. 0.6-15-gbeab8b2
Andreas B. Mundt
andi at debian.org
Sun Sep 2 07:01:24 UTC 2012
The following commit has been merged in the squeeze branch:
commit 1a9850f2523af81c0a5e1e9aaf5d8fc58f93ca1a
Author: Andreas B. Mundt <andi at debian.org>
Date: Sun Aug 26 18:19:39 2012 +0200
Implement system backup. Cherry-pick from master branch.
Backup /etc/ and home directories (dirvish), LDAP (slapcat) and the
package and debconf selection.
Add disk_config/* for extra backup disk.
Use UUID in fstab.
diff --git a/fai/config/class/50-host-classes b/fai/config/class/50-host-classes
index 8bb8e12..ee531e1 100755
--- a/fai/config/class/50-host-classes
+++ b/fai/config/class/50-host-classes
@@ -19,6 +19,7 @@
##
## LVM*_A | RAIDLVM*_A RAID --> RAID1 (mirroring)
##
+## *BAK_A --> extra backup disk
##
## Example classes that might be added:
##
@@ -28,9 +29,13 @@
##
FLAVOR="LVM6_A"
-#FLAVOR="RAIDLVM6_A RAID"
-#FLAVOR="LVM7_A DISKLESS_SERVER"
-#FLAVOR="RAIDLVM7_A RAID DISKLESS_SERVER"
+#FLAVOR="LVM6BAK_A" ## backup disk
+#FLAVOR="RAIDLVM6_A RAID" ## RAID1
+#FLAVOR="RAIDLVM6BAK_A RAID" ## RAID1, backup disk
+#FLAVOR="LVM7_A DISKLESS_SERVER" ## diskless
+#FLAVOR="LVM7BAK_A DISKLESS_SERVER" ## diskless, backup disk
+#FLAVOR="RAIDLVM7_A RAID DISKLESS_SERVER" ## diskless, RAID1
+#FLAVOR="RAIDLVM7BAK_A RAID DISKLESS_SERVER" ## diskless, RAID1, backup disk
MAINSERVER_A="$FLAVOR LOG_SERVER PROXY NTP_SERVER DNS_SERVER NFS_SERVER \
LDAP_CLIENT LDAP_SERVER KERBEROS_CLIENT KERBEROS_KDC KDC_LDAP SERVER_A"
diff --git a/fai/config/disk_config/LVM6_A b/fai/config/disk_config/LVM6BAK_A
similarity index 84%
copy from fai/config/disk_config/LVM6_A
copy to fai/config/disk_config/LVM6BAK_A
index 7654bb8..bf70d64 100644
--- a/fai/config/disk_config/LVM6_A
+++ b/fai/config/disk_config/LVM6BAK_A
@@ -9,3 +9,7 @@ vg_system-root / 1G-2G ext3 errors=remount-ro
vg_system-usr /usr 2G-20G ext3 defaults
vg_system-var /var 1G-20G ext3 defaults
vg_system-home /lan/mainserver/home0 2G-70% ext3 defaults
+
+
+disk_config disk2 fstabkey:uuid
+primary /backup 100% ext3 defaults
diff --git a/fai/config/disk_config/LVM7_A b/fai/config/disk_config/LVM7BAK_A
similarity index 86%
copy from fai/config/disk_config/LVM7_A
copy to fai/config/disk_config/LVM7BAK_A
index e8298f2..1218043 100644
--- a/fai/config/disk_config/LVM7_A
+++ b/fai/config/disk_config/LVM7BAK_A
@@ -10,3 +10,7 @@ vg_system-usr /usr 2G-20G ext3 defaults
vg_system-var /var 1G-20G ext3 defaults
vg_system-opt /opt 4G-10G ext3 defaults
vg_system-home /lan/mainserver/home0 2G-70% ext3 defaults
+
+
+disk_config disk2 fstabkey:uuid
+primary /backup 100% ext3 defaults
diff --git a/fai/config/disk_config/RAIDLVM6_A b/fai/config/disk_config/RAIDLVM6BAK_A
similarity index 72%
copy from fai/config/disk_config/RAIDLVM6_A
copy to fai/config/disk_config/RAIDLVM6BAK_A
index 694d970..c6c2deb 100644
--- a/fai/config/disk_config/RAIDLVM6_A
+++ b/fai/config/disk_config/RAIDLVM6BAK_A
@@ -1,4 +1,4 @@
-## RAID1 on two identical disks.
+## RAID1 on two identical disks and a backup disk.
disk_config disk1
primary - 64-256 - -
@@ -8,15 +8,19 @@ logical - 0- - -
disk_config disk2 sameas:disk1
-disk_config raid
+disk_config raid fstabkey:uuid
raid1 /boot disk1.1,disk2.1 ext3 rw
raid1 swap disk1.2,disk2.2 swap sw
raid1 - disk1.5,disk2.5 - -
-disk_config lvm
+disk_config lvm fstabkey:uuid
vg vg_system md2
vg_system-root / 1G-2G ext3 errors=remount-ro
vg_system-usr /usr 2G-20G ext3 defaults
vg_system-var /var 1G-20G ext3 defaults
vg_system-home /lan/mainserver/home0 2G-70% ext3 defaults
+
+
+disk_config disk3 fstabkey:uuid
+primary /backup 100% ext3 defaults
diff --git a/fai/config/disk_config/RAIDLVM6_A b/fai/config/disk_config/RAIDLVM6_A
index 694d970..2421a67 100644
--- a/fai/config/disk_config/RAIDLVM6_A
+++ b/fai/config/disk_config/RAIDLVM6_A
@@ -8,13 +8,13 @@ logical - 0- - -
disk_config disk2 sameas:disk1
-disk_config raid
+disk_config raid fstabkey:uuid
raid1 /boot disk1.1,disk2.1 ext3 rw
raid1 swap disk1.2,disk2.2 swap sw
raid1 - disk1.5,disk2.5 - -
-disk_config lvm
+disk_config lvm fstabkey:uuid
vg vg_system md2
vg_system-root / 1G-2G ext3 errors=remount-ro
vg_system-usr /usr 2G-20G ext3 defaults
diff --git a/fai/config/disk_config/RAIDLVM7_A b/fai/config/disk_config/RAIDLVM7BAK_A
similarity index 73%
copy from fai/config/disk_config/RAIDLVM7_A
copy to fai/config/disk_config/RAIDLVM7BAK_A
index 2e008d1..095369c 100644
--- a/fai/config/disk_config/RAIDLVM7_A
+++ b/fai/config/disk_config/RAIDLVM7BAK_A
@@ -1,4 +1,4 @@
-## RAID1 on two identical disks.
+## RAID1 on two identical disks and a backup disk.
disk_config disk1
primary - 64-256 - -
@@ -8,16 +8,20 @@ logical - 0- - -
disk_config disk2 sameas:disk1
-disk_config raid
+disk_config raid fstabkey:uuid
raid1 /boot disk1.1,disk2.1 ext3 rw
raid1 swap disk1.2,disk2.2 swap sw
raid1 - disk1.5,disk2.5 - -
-disk_config lvm
+disk_config lvm fstabkey:uuid
vg vg_system md2
vg_system-root / 1G-2G ext3 errors=remount-ro
vg_system-usr /usr 2G-20G ext3 defaults
vg_system-var /var 1G-20G ext3 defaults
vg_system-opt /opt 4G-10G ext3 defaults
vg_system-home /lan/mainserver/home0 2G-70% ext3 defaults
+
+
+disk_config disk3 fstabkey:uuid
+primary /backup 100% ext3 defaults
diff --git a/fai/config/disk_config/RAIDLVM7_A b/fai/config/disk_config/RAIDLVM7_A
index 2e008d1..76dc5ae 100644
--- a/fai/config/disk_config/RAIDLVM7_A
+++ b/fai/config/disk_config/RAIDLVM7_A
@@ -8,13 +8,13 @@ logical - 0- - -
disk_config disk2 sameas:disk1
-disk_config raid
+disk_config raid fstabkey:uuid
raid1 /boot disk1.1,disk2.1 ext3 rw
raid1 swap disk1.2,disk2.2 swap sw
raid1 - disk1.5,disk2.5 - -
-disk_config lvm
+disk_config lvm fstabkey:uuid
vg vg_system md2
vg_system-root / 1G-2G ext3 errors=remount-ro
vg_system-usr /usr 2G-20G ext3 defaults
diff --git a/fai/config/files/etc/cron.daily/backup/SERVER_A b/fai/config/files/etc/cron.daily/backup/SERVER_A
new file mode 100755
index 0000000..92aa8fb
--- /dev/null
+++ b/fai/config/files/etc/cron.daily/backup/SERVER_A
@@ -0,0 +1,80 @@
+#!/bin/bash
+#
+# backup ldap, package selection and debconf values
+# run dirvish
+#
+
+set -e
+
+DIR="/backup/"
+LDIF_DIR="${DIR}/ldap/"
+DPKG_DIR="${DIR}/dpkg/"
+DATE=`date +%F`
+
+# from dirvish:
+mount_check() {
+ mntout=`tempfile -p mount`
+ mount $1 >$mntout 2>&1
+ if [ ! -d $1/lost+found ]; then # only works for "real" filesystems :-)
+ # (Yes, I know about reiserfs.)
+ echo "'mount $1' failed?! Stopping."
+ echo "mount output:"
+ cat $mntout
+ rm -f $mntout
+ exit 2
+ fi
+
+ if stat $1 | grep 'Inode: 2[^0-9]' >/dev/null; then # ditto
+ rm -f $mntout
+ return 0 # ok
+ fi
+ echo "$1 isn't inode 2 ?! Mount must have failed; stopping."
+ echo ''
+ stat $1
+ echo "mount output:"
+ cat $mntout
+ rm -f $mntout
+ umount $1
+ exit 2
+}
+
+
+if grep -q ${DIR%/} /etc/fstab ; then
+ MNT=true
+ mount_check $DIR
+ trap "rc=$?; umount $DIR; exit $rc" ERR
+fi
+
+## backup ldap:
+if [ -x /usr/sbin/slapcat ] ; then
+ if [ ! -d $LDIF_DIR ] ; then
+ mkdir -p $LDIF_DIR
+ chmod 750 $LDIF_DIR
+ fi
+ slapcat -l $LDIF_DIR/$DATE.ldif
+ gzip -f $LDIF_DIR/$DATE.ldif
+fi
+
+## backup package selection and debconf data:
+if [ ! -d $DPKG_DIR ] ; then
+ mkdir -p $DPKG_DIR
+ chmod 750 $DPKG_DIR
+fi
+
+dpkg --get-selections > $DPKG_DIR/$DATE.dpkg
+gzip -f $DPKG_DIR/$DATE.dpkg
+debconf-get-selections > $DPKG_DIR/$DATE.debconf
+gzip -f $DPKG_DIR/$DATE.debconf
+
+## dirvish:
+if [ ! -x /usr/sbin/dirvish-expire ]; then exit 0; fi
+if [ ! -s /etc/dirvish/master.conf ]; then exit 0; fi
+
+/usr/sbin/dirvish-expire --quiet && /usr/sbin/dirvish-runall --quiet
+rc=$?
+
+if [ $MNT ] ; then
+ umount $DIR || rc=$?
+fi
+
+exit $rc
diff --git a/fai/config/package_config/SERVER_A b/fai/config/package_config/SERVER_A
index cbd4e61..d707f9e 100644
--- a/fai/config/package_config/SERVER_A
+++ b/fai/config/package_config/SERVER_A
@@ -5,5 +5,8 @@ sudo-ldap
screen
etckeeper
+## backup:
+dirvish
+
PACKAGES aptitude KERBEROS_KDC
krb5-kdc-ldap
diff --git a/fai/config/scripts/SERVER_A/70-dirvish b/fai/config/scripts/SERVER_A/70-dirvish
new file mode 100755
index 0000000..a3b3224
--- /dev/null
+++ b/fai/config/scripts/SERVER_A/70-dirvish
@@ -0,0 +1,66 @@
+#!/bin/bash
+#
+# configure dirvish
+
+set -e
+
+## all backed up directories:
+BANK_DIRS="/etc /lan/mainserver/home0"
+
+BACKUP_DIR="/backup/"
+
+mkdir -vp $BACKUP_DIR
+fcopy -v /etc/cron.daily/backup
+rm -vf $target/etc/cron.d/dirvish
+
+cat > $target/etc/dirvish/master.conf <<EOF
+bank:
+ $BACKUP_DIR
+exclude:
+ lost+found/
+ core
+ *~
+ .nfs*
+Runall:
+EOF
+
+for DIR in $BANK_DIRS ; do
+ ID=`basename $DIR`
+ echo " $ID 22:00" >> $target/etc/dirvish/master.conf
+done
+cat >> $target/etc/dirvish/master.conf <<EOF
+expire-default: +15 days
+expire-rule:
+# MIN HR DOM MON DOW STRFTIME_FMT
+ * * * * 1 +3 months
+ * * 1-7 * 1 +1 year
+ * * 1-7 1,4,7,10 1
+ * 10-20 * * * +4 days
+# * * * * 2-7 +15 days
+EOF
+
+for DIR in $BANK_DIRS ; do
+ ID=`basename $DIR`
+ echo "Creating dirvish config $ID for $DIR."
+ mkdir -v -p $target/$BACKUP_DIR/$ID/dirvish/
+ chmod 750 $target/$BACKUP_DIR/$ID
+ cat > $target/$BACKUP_DIR/$ID/dirvish/default.conf <<EOF
+client: $HOSTNAME
+tree: $DIR
+xdev: 1
+index: gzip
+image-default: %Y%m%d
+exclude:
+*.bak
+EOF
+done
+
+if [ $FAI_ACTION == "install" ] ; then
+ for DIR in $BANK_DIRS ; do
+ ID=`basename $DIR`
+ echo "Initialize dirvish vault $ID for $DIR:"
+ $ROOTCMD dirvish --vault $ID --init
+ done
+ ## do not mount backup partition on boot (noauto):
+ sed -i "s#\(.\+${BACKUP_DIR%/}.\+\)defaults\(.\+\)#\1noauto\2#" $target/etc/fstab
+fi
--
Debian-LAN development and packaging
More information about the debian-lan-devel
mailing list