[debian-lan-devel] [SCM] Debian-LAN development and packaging branch, master, updated. 0.6-32-g21f7955
Andreas B. Mundt
andi at debian.org
Tue Aug 28 11:33:15 UTC 2012
The following commit has been merged in the master branch:
commit b93c02c4002422caa53f59807e65f967f3d645f5
Author: Andreas B. Mundt <andi at debian.org>
Date: Sun Aug 26 18:19:39 2012 +0200
Implement system backup.
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 ae4a177..cc1f0e9 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/LVM7_A b/fai/config/disk_config/LVM6BAK_A
similarity index 84%
copy from fai/config/disk_config/LVM7_A
copy to fai/config/disk_config/LVM6BAK_A
index e6720d1..b52761b 100644
--- a/fai/config/disk_config/LVM7_A
+++ b/fai/config/disk_config/LVM6BAK_A
@@ -8,5 +8,8 @@ vg vg_system disk1.5
vg_system-root / 1G-2G ext4 errors=remount-ro
vg_system-usr /usr 2G-20G ext4 defaults
vg_system-var /var 1G-20G ext4 defaults
-vg_system-opt /opt 4G-10G ext4 defaults
vg_system-home /lan/mainserver/home0 2G-70% ext4 defaults
+
+
+disk_config disk2 fstabkey:uuid
+primary /backup 100% ext4 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 e6720d1..2d968c4 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 ext4 defaults
vg_system-var /var 1G-20G ext4 defaults
vg_system-opt /opt 4G-10G ext4 defaults
vg_system-home /lan/mainserver/home0 2G-70% ext4 defaults
+
+
+disk_config disk2 fstabkey:uuid
+primary /backup 100% ext4 defaults
diff --git a/fai/config/disk_config/RAIDLVM7_A b/fai/config/disk_config/RAIDLVM6BAK_A
similarity index 72%
copy from fai/config/disk_config/RAIDLVM7_A
copy to fai/config/disk_config/RAIDLVM6BAK_A
index 20861cf..a64da25 100644
--- a/fai/config/disk_config/RAIDLVM7_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,16 +8,19 @@ logical - 0- - -
disk_config disk2 sameas:disk1
-disk_config raid
+disk_config raid fstabkey:uuid
raid1 /boot disk1.1,disk2.1 ext4 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 ext4 errors=remount-ro
vg_system-usr /usr 2G-20G ext4 defaults
vg_system-var /var 1G-20G ext4 defaults
-vg_system-opt /opt 4G-10G ext4 defaults
vg_system-home /lan/mainserver/home0 2G-70% ext4 defaults
+
+
+disk_config disk3 fstabkey:uuid
+primary /backup 100% ext4 defaults
diff --git a/fai/config/disk_config/RAIDLVM6_A b/fai/config/disk_config/RAIDLVM6_A
index 035c794..4efc6f3 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 ext4 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 ext4 errors=remount-ro
vg_system-usr /usr 2G-20G ext4 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 20861cf..80d0345 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 ext4 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 ext4 errors=remount-ro
vg_system-usr /usr 2G-20G ext4 defaults
vg_system-var /var 1G-20G ext4 defaults
vg_system-opt /opt 4G-10G ext4 defaults
vg_system-home /lan/mainserver/home0 2G-70% ext4 defaults
+
+
+disk_config disk3 fstabkey:uuid
+primary /backup 100% ext4 defaults
diff --git a/fai/config/disk_config/RAIDLVM7_A b/fai/config/disk_config/RAIDLVM7_A
index 20861cf..79f8b94 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 ext4 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 ext4 errors=remount-ro
vg_system-usr /usr 2G-20G ext4 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 7b6a92e..1f6b240 100644
--- a/fai/config/package_config/SERVER_A
+++ b/fai/config/package_config/SERVER_A
@@ -6,5 +6,9 @@ screen
exim4 nullmailer-
etckeeper
+## backup:
+dirvish
+#apt-clone
+
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