All pastes #350390 Raw Edit

lvm-backup,dummy.sh

public shellscript v1 · immutable
·published 2007-02-11 12:05 UTC
rendered paste body
#! /bin/sh# Für Debug: Ausführliche Ausgabenset -xbackup_dir="$1"# Pfad zum vol_id Programm angeben - wird mit udev geliefert.VOL_ID="/lib/udev/vol_id"# Partitionstabelle auslesensfdisk -d > "$backup_dir/sfdisk.txt"# Vorhandene PVs, VGs und LVs auslesenpvdisplay -C --noheadings > "$backup_dir/pvdisplay.txt"vgdisplay -C --noheadings > "$backup_dir/vgdisplay.txt"lvdisplay -C --noheadings --units m > "$backup_dir/lvdisplay.txt"# Mountverzeichnis für root anlegenmkdir /tmp/backup.root.$$# Root in das Mountverzeichnis einhängenmount -v -o bind / /tmp/backup.root.$$# In das Mountverzeichnis wechselnpushd /tmp/backup.root.$$ > /dev/null 2>&1# Für Debug: Keine Backupdateien erzeugen## Root sichern#find . -print0 | cpio -o0aB -H crc > "$backup_dir/root.cpio"# Das Mountverzeichnis verlassenpopd > /dev/null 2>&1# Das Mountverzeichnis aushängen und löschenumount /tmp/backup.root.$$ && rm -rfv /tmp/backup.root.$$# Mountverzeichnis für boot anlegenmkdir /tmp/backup.boot.$$# boot einhängen - richtig, falls noch nicht gemounted, per bind andernfallsif grep -q /boot /proc/mounts; then	# /boot per -o bind einhängen, da es schon gemounted ist	mount -v -o bind /boot /tmp/backup.boot.$$else	# /boot ist noch nicht gemounted - richtig einhängen	# Dazu bestimmen, auf welchem Blockdevice es sich befindet	mount -v -o ro `grep boot /etc/fstab | grep -v ^# | awk '{print $1}'` /tmp/backup.boot.$$fi# Liste aller Mounts sichern, mit Angabe der Labelsmount -l > "$backup_dir/mount.txt"# In das Mountverzeichnis wechselnpushd /tmp/backup.boot.$$ > /dev/null 2>&1# Für Debug: Keine Backupdateien erzeugen## /boot sichern#find . -print0 | cpio -o0aB -H crc > "$backup_dir/boot.cpio"# Das Mountverzeichnis verlassenpopd > /dev/null 2>&1# Das Mountverzeichnis aushängen und löschenumount /tmp/backup.boot.$$ && rm -rfv /tmp/backup.boot.$$# Alle LVs sichernlvdisplay -C --noheadings --units m | while read lv vg opt size; do	# Sofern Swap auf diesem Device angelegt ist, überspringe	# dieses Device.	# Hierzu wird auf ein Tool von udev zurückgegriffen, sofern	# vorhanden.	if test -x "$VOL_ID"; then		# Das vol_id Programm wurde gefunden - verwende es!		if "$VOL_ID" -t /dev/$vg/$lv | grep -qi swap; then			# Es handelt sich um ein Swapdevice -> mit 			# dem nächsten Device weitermachen.			continue		fi	fi	# Snapshot LV anlegen	lvcreate --snapshot --name Snap-$lv --size 512m /dev/$vg/$lv	# Mountverzeichnis anlegen	mkdir /tmp/snaps_Snap-$lv.$$	# Snapshot LV einhängen - XFS & Rest mit unterschiedlichen Optionen	if [ "`egrep "${vg}.*${lv}" /proc/mounts | awk '{print $3}'`" = "xfs" ]; then		opts=ro,nouuid	else		opts=ro	fi	# Snapshot LV einhängen	mount -v -o $opts /dev/$vg/Snap-$lv /tmp/snaps_Snap-$lv.$$	# In das Mountverzeichnis wechseln	pushd /tmp/snaps_Snap-$lv.$$ > /dev/null 2>&1        # Für Debug: Keine Backupdateien erzeugen	## Das Dateisystem sichern	#find . -print0 | cpio -o0aB -H crc > "$backup_dir/${vg}_$lv.cpio"	# Das Mountverzeichnis verlassen	popd > /dev/null 2>&1	# Das Mountverzeichnis aushängen und löschen	umount -v /dev/$vg/Snap-$lv && rm -rfv /tmp/snaps_Snap-$lv.$$	# Snapshot LV entfernen	lvremove --force /dev/$vg/Snap-$lvdone