Horshack’s
very
own site
This is Bavaria, Germany!
You will find links to Perl,
bootdisks for system administration,
a lot of Linux,
Windows administration
and some personal belongings.
Vserver: Backup/restore, do it fast
Vserver: Backup/restore, do it FAASSSSSST!
- My goal
- Keep it simple? No, keep it simpler!
- Working for dooms day: the way to backup
My goal
I want to restore a Linuxserver with Vservers installed as fast as possible.
Keep it simple? No, keep it simpler!
If you want to restore superfast think what can happen:
- Crash of harddisk.
- Fire or computer gets stolen.
- New installed software for testing destroys production server.
- Usertrouble (deleted or destroyed files) is standard, your normal backup-procedures
apply...
How
to react:
- SIMPLE hardware.
- Harddisk:
- No hardwareraids with special drivers.
- No softwareraids.
- Take
a ATA-harddisk not too big, not over 120 Gigabytes (128 GByte-trouble!). The smaller, the better.
- The mothersystem lies
on one filesystem.
- No extra boot-partition. When you are mounting one fs, you
have everything all right, all files for the mother-server are available.
- Standard, standard,
standard. Ext2-filesystem, no Ext3, no XFS, no Reiser on the mother-system.
It's not worth
the trouble when you are in biiiig stress!
- Network:
- No cheap network adapters with special drivers or not to get bought
after one year
- Take a 3com 3c905 100 MBit-card, you will get it anytime, anywhere.
You can lend one from your neighbour when your stock is empty.
- Standard-motherboard, standard-CPU (Intel, not AMD)
- Install nearly nothing on this system!
Think! This is about desaster recovery! This is about your nerves! Keep it
simple, keep it standard!
On the picture you see how my system with vservers is built up.
Working for dooms day: backup your mothersystem
I backup to a large fileserver with Windows 2000 which itself gets backed
up daily.
Create a disaster-backup of the mother-system:
- Backup of full mothersystem, track by track
Create a backup
_and_ restore it to another harddisk. It's worth nothing if you didn't
test the recovery!
- Backup with Ghost:
There seem to be problems with ghost
when trying to make partition-images from Linux-partition. You have
to prove wether it works for you.
- Backup with partimage. Get a rescue-CD from http://www.sysresccd.org,
boot with it:
# mkdir /mnt/sambaserver
# smbmount //sambaserver/share /mnt/sambaserver -o username=yourname,password=yourpass,workgroup=yourworkgroup
Backup your MBR first, because you love to forget this:
# dd
if=/dev/hda of=/mnt/sambaserver/mother_hda.mbr bs=512 count=1
Backup
your whole first partition hda1, the partition of the mothership:
#
partimage --nodesc --compress=1 save /dev/hda1 /mnt/sambaserver/mother_hda1
- Don't backup ext3-data-partition /dev/hda3 because you will
do daily/weekly tar- or rsync-backups.
Partimage and Ghost seem
to have a lot of problems with ext3, although it should simply work.
But it doesn't. You will get problems only at recovery time which is
more that bad!
- Don't backup swap-partition /dev/hda2
- Reboot your system and document your system with this shellscript
#!/bin/sh
# File: /root/bin/doku_server.sh
set -x
SERVER=tanzwut
# Get partition sizes
fdisk -l /dev/hda >${SERVER}_fdisk
# Get ip-addresses
ifconfig >${SERVER}_ifconfig
# Get packages of mothership
dpkg --get-selections \* >${SERVER}_pakete
# Get hostname-lookup, nameserver
cat /etc/resolv.conf >${SERVER}_resolv
# Get mounted filesystems
cat /etc/fstab >${SERVER}_fstab
ls -l ${SERVER}*
- Save these files to a safe documentation place. Most important:
fdisk with partition sizes.
- Again: restore your backup to another harddisk and test it.
Plan A: Daily backup to USB harddisks
This is a pretty good idea! USB-harddisk
are large and cheap. You can transport them to a safe place easily.
But USB, also USB-2, is slow. So you will not
like to do full backups. But you must do backups as often as possible. Every
other month is not enough!
Solution: backup to USB-harddisk with rsync. Take this script as an idea:
#!/bin/sh
DESTINATION=/mnt/sda1
DESTDEVICE=/dev/sda1
echo "Shutdown all vservers, backup to $DESTINATION"
echo Press RETURN to start
read $RETURN
# Stop all vservers
# You could do this with /etc/init.d/vserver stop
vserver ap1 stop
vserver ap2 stop
vserver home stop
vserver mail stop
vserver media stop
vserver mysql3 stop
vserver netser stop
echo Mounting backup usb-harddisk
mount -t ext3 $DESTDEVICE $DESTINATION
# not here:
# echo Mounting smb-fs
# mount -t smbfs //sambaserver/share $DESTINATION \
# -o username=yourname,password=yourpass,workgroup=yourworkgroup
echo Backup mothership without data
mkdir $DESTINATION/mothership 2>/dev/null
OPTIONEN="--archive \
--verbose \
--progress \
--perms \
--delete \
--delete-excluded"
EXCLUDE="--exclude /data \
--exclude /mnt \
--exclude /proc"
rsync $OPTIONEN \
$EXCLUDE \
/ \
$DESTINATION/mothership/
echo Backup all vservers which live in /data
mkdir $DESTINATION/data 2>/dev/null
EXCLUDE="--exclude /mnt \
--exclude /proc"
rsync $OPTIONEN \
$EXCLUDE \
/data \
$DESTINATION
date >$DESTINATION/backupdate.txt
echo Start all vservers
vserver netser start
vserver ap1 start
vserver ap2 start
vserver home start
vserver mail start
vserver media start
vserver mysql3 start
echo Ready with backup
date
df -h
umount $DESTDEVICE
Backup to two harddisks, at least. Your rule should be:
There is always a new backup on one of
the disk, you will never delete the newest backup.
Plan B: Daily backup to Samba-fileserver
Backup to a large fileserver via network with Windows 2000 which itself
gets backed up daily.
- Install SMB on your mothersystem:
apt-get install smbclient
smbfs
- Mount an SMB-filesystem:
mother# mount -t smbfs //sambaserver/share /mnt/sambaserver -o username=yourname,password=yourpass,workgroup=yourworkgroup
- Backup like in Plan A
Working for dooms day: the way to document
Let this run on the mothership. Put output-files to a safe place.
#!/bin/sh
# File: /root/bin/doku_server.sh
set -x
SERVER=tanzwut
# Get partition sizes
fdisk -l /dev/hda >${SERVER}_fdisk
# Get ip-addresses
ifconfig >${SERVER}_ifconfig
# Get packages of mothership
dpkg --get-selections \* >${SERVER}_pakete
# Get hostname-lookup, nameserver
cat /etc/resolv.conf >${SERVER}_resolv
# Get mounted filesystems
cat /etc/fstab >${SERVER}_fstab
ls -l ${SERVER}*
Put an iso-image of your rescue-CD to that safe place: http://www.sysresccd.org
or have at least one available.
Dooms day: how to recover totally
Have this ready:
- New system with new harddisk like the old one: ATA-disk as first master,
so that /dev/hda on the old system is /dev/hda on the new one.
- Rescue-CD from http://www.sysresccd.org
- A printout of fstab of crashed system.
Do this:
- Boot with rescue-disk
- fdisk /dev/hda
- Delete all partitions on the harddisk
- Partition your harddisk:
/dev/hda1 => 5 GBytes, Type 82, boot
(type a for that)
/dev/hda2 => 1 GByte, Type 83 (type
t for that)
/dev/hda3 => Rest of harddisk, boot, Type 83
- Create filesystems
- Not for /dev/hda1, you will recover this in a minute from the image-file
- # mkswap /dev/hda2
- # mke2fs /dev/hda3
- # tune2fs -j /dev/hda3
- Mount your sambaserver with the root-device-image and the mbr-file
#
mkdir /mnt/sambaserver
# mount -t smbfs \
-o username=yourname,password=yourpass,workgroup=yourworkgroup
\
//sambaserver/share /mnt/sambaserver
# partimage restore
/dev/hda1 /mnt/sambaserver
# dd if=/mnt/sambaserver/mother_hda.mbr
of=/dev/hda
- Reboot to get the mothership running
- Restore /data-partition with vservers with untar or whatever you have
as software