Backup zroot mit zfs receive klappt nicht

Frank

Anfänger
Hallo,

mein Ziel ist es, dass ich bequem meinen kompletten zroot-Pool in einem Snapshot sichere, um diesen bei Bedarf möglichst einfach wieder zurück zu spielen.

Bisher gehe ich so vor.
Vielleicht gibt es ja einen einfacheren Weg, bin für jeden Tip mehr als dankbar.


Installieren tue ich das System mit folgendem Skript:
Code:
#!/bin/sh
# Boot from a install-medium
# kbdmap
# ifconfig em0 192.168.0.1
# mkdir /tmp/mynfs
# mount -v 192.168.0.35:/home/user/nfs /tmp/mynfs
# execute this script
DISK0=ada0

zpool destroy zroot
gpart destroy -F $DISK0

gpart create -s gpt $DISK0
gpart add -a 4k -s 512k -t freebsd-boot $DISK0
gpart add -a 4k -s 20G -t freebsd-swap -l swap0 $DISK0
gpart add -a 4k -s 200GB -t freebsd-zfs -l disk0 $DISK0
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 $DISK0


# always align at 4K
gnop create -S 4096 /dev/gpt/disk0
zpool create -f -o altroot=/mnt -o cachefile=/var/tmp/zpool.cache zroot  /dev/gpt/disk0.nop
zpool export  zroot
gnop destroy /dev/gpt/disk0.nop
zpool import -o altroot=/mnt -o cachefile=/var/tmp/zpool.cache zroot

#setup pool
zpool set bootfs=zroot zroot
zfs set checksum=fletcher4 zroot
zfs set atime=off zroot

zfs create zroot/usr
zfs create zroot/usr/home
zfs create zroot/var

zfs create -o compression=on -o exec=on -o setuid=off zroot/tmp
zfs create -o compression=gzip-9 -o setuid=off zroot/usr/ports
zfs create -o compression=off -o exec=off -o setuid=off zroot/usr/ports/distfiles
zfs create -o compression=off -o exec=off -o setuid=off zroot/usr/ports/packages
zfs create -o compression=gzip-9 -o exec=off -o setuid=off zroot/usr/src
zfs create -o compression=lzjb -o exec=off -o setuid=off zroot/var/crash
zfs create -o exec=off -o setuid=off zroot/var/db
zfs create -o compression=lzjb -o exec=on -o setuid=off zroot/var/db/pkg
zfs create -o exec=off -o setuid=off zroot/var/empty
zfs create -o compression=lzjb -o exec=off -o setuid=off zroot/var/log
zfs create -o compression=gzip -o exec=off -o setuid=off zroot/var/mail
zfs create -o exec=off -o setuid=off zroot/var/run
zfs create -o compression=lzjb -o exec=on -o setuid=off zroot/var/tmp

#fix permissions
chmod 1777 /mnt/tmp
cd /mnt ; ln -s usr/home home
chmod 1777 /mnt/var/tmp

#install FreeBSD
cd /usr/freebsd-dist
export DESTDIR=/mnt
for file in base.txz kernel.txz doc.txz src.txz; #ports.txz lib32.txz
do (cat $file | tar --unlink -xpJf - -C ${DESTDIR:-/}); done

#final configuration
cp /var/tmp/zpool.cache /mnt/boot/zfs/zpool.cache
echo 'zfs_enable="YES"' >> /mnt/etc/rc.conf
echo 'keymap="german.iso"' >> /mnt/etc/rc.conf
echo 'zfs_load="YES"' >> /mnt/boot/loader.conf
echo 'vfs.root.mountfrom="zfs:zroot"' >> /mnt/boot/loader.conf
echo 'LOADER_ZFS_SUPPORT=YES' > /mnt/etc/src.conf

echo 'WRKDIRPREFIX=/usr/obj' >> /mnt/etc/make.conf

touch /mnt/etc/fstab

echo '/dev/gpt/swap0 none swap sw 0 0' >> /mnt/etc/fstab
zfs set readonly=on zroot/var/empty

#reboot into the new system
#passwd root
#tzsetup
#cd /etc/mail ; make aliases

#???echo 'WITH_PKGNG=yes' >> /etc/make.conf
#???in login.conf eintragen:
##:charset=UTF-8:\
##:lang=de_DE.UTF-8:\

# Remember to rebuild the database after each change to the
# file /etc/login.conf
#cap_mkdb /etc/login.conf

Das läuft soweit.
Habe mehrmals gebootet und ein paar Ports installiert.
Oder übersehe ich schon was?

So erstelle ich den Snapshot:
Code:
#!/bin/sh

timestamp=`date +%y%m%d_%H:%M:%S`

zfs snapshot -r zroot@$timestamp
zfs list -r -t snapshot zroot
zfs send -Rv zroot@$timestamp | gzip > /zbackup/full_system_backup_$timestamp.zfs.gz

zfs destroy -r zroot@$timestamp
zfs list -r -t snapshot zroot
exit 0

Das schein nach meiner Ansicht nach auch zu funktionieren.

Um das System jetzt mit Hilfe des Snapshots zurück zu setzen mache ich folgendes, was aber nicht klappt:

Code:
#!/bin/sh
# Boot from a install-medium and start the script.
# kbdmap
# ifconfig em0 192.168.0.1
# mkdir /tmp/mynfs
# mount -v 192.168.0.35:/home/uer/nfs  /tmp/mynfs
# execute this script

DISK0=ada0

zpool destroy zroot
gpart destroy -F $DISK0

gpart create -s gpt $DISK0
gpart add -a 4k -s 512k -t freebsd-boot $DISK0
gpart add -a 4k -s 20G -t freebsd-swap -l swap0 $DISK0
gpart add -a 4k -s 200GB -t freebsd-zfs -l disk0 $DISK0
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 $DISK0


zpool create -f -o altroot=/mnt -o cachefile=/var/tmp/zpool.cache zroot  /dev/gpt/disk0.nop
zpool export  zroot
gnop destroy /dev/gpt/disk0.nop
zpool import -o altroot=/mnt -o cachefile=/var/tmp/zpool.cache zroot

#setup pool
zpool set bootfs=zroot zroot
zfs set checksum=fletcher4 zroot
zfs set atime=off zroot

# die kommenden Schritte führe ich händisch in der Shell
# der Live-CD aus
mkdir /tmp/zbackup
zpool import -f zbackup
zfs set mountpoint=/tmp/zbackup zbackup
zfs mount zbackup
gunzip -c /tmp/boot/zfs/zbackup/full.... | zfs receive -vdF zroot
zpool export zbackup
cp /var/tmp/zpool.cache /mnt/boot/zfs/zpool.cache
zfs set mountpoint=legacy zroot
zfs unmount -a
reboot

Das System bootet auch.
Nur kommt gegen Ende des Bootvorgangs:
init: can't exec getty '/usr/libexec/gett' for port /dev/ttyv5 No such file or directory
kurz vorher findet er sed und egrep nicht.
Ich vermute, dass ich was mit den Mountpoints verbocke.

Die zpool.cache kopiere ich doch richtig, sonst würde das System doch gar nicht booten.

Ich komm irgendwie nicht weiter und gegoogelt und gelesen habe ich auch schon eine Weile.

Vielen Dank
 
Code:
zfs send -Rv zroot@$timestamp | gzip > /zbackup/full_system_backup_$timestamp.zfs.gz
Hast du mal geprüft, ob er hier wirklich alle Dateisysteme sichert? Deine Beschreibung klingt etwas danach, als ob er nach dem Restore lediglich / zur Verfügung hat. Alles darunter scheint nicht wiederhergestellt oder gemountet zu werden.
 
Habs Danke.

Lag an den Mountpoints.

zfs set mountpoint=/usr zroot/usr
zfs set mountpoint=/var zroot/var

hat beim Wiederherstellen gefehlt.

Noch ein paar Tests und ich kann meinen Homeserver neu aufsetzen.
 
Zurück
Oben