Backup Xen virtual machines with LVM snapshots and ftplicity/duplicity
Some time ago, I updated the backup system on a Server running multiple Xen VM instances (DomUs). Before changing the system, each virtual machine ran its own backup scripts to backup data to an external FTP server. Now, VMs are centrally backed up to FTP from the Dom0 using LVM (Logical Volume Manager) snapshots. As a backup solution I chose duplicity and ftplicity in combination with a shellscript to create automated LVM snapshots. Duplicity is a tool to create GPG-encrypted (this way you can store your backups at remote servers without having to worry about who has access to your data) incremental backups to remote servers, ftplicity is a wrapper script for duplicity which allows running duplicity without interaction (e.g. without the need to type any passwords). Ftplicity was originally published by the German computer magazine c’t, but has been undergone further development and is now hosted at SourceForge.
You can find tutorials on ftplicity/duplicity here (Note: they use the original c’t version of ftplicity):
- http://www.weareroot.de/2007/08/17/ftplicity-inkrementelle-backups-sicher-ablegen/ (German)
- http://www.howtoforge.com/ftp-backups-with-duplicity-ftplicity-debian-etch
Basically you can use this setup for any kind of LVM snapshot based system, but I’m focusing on backing up Xen VMs here. I assume you got your LVM and Xen system up and running so far. I did this on a Debian Lenny system, but it should be similar on other distros. I did all steps as root.
MySQL backup user
To create a backup user for MySQL you need at least the following privileges (to use mysqldump):
GRANT SELECT, SHOW VIEW, LOCK TABLES ON *.* TO 'backup'@'localhost';
Linux Software RAID1 defekte Platte tauschen
Da auf meinem Rootserver zum wiederholten Mal Probleme mit der zweiten Festplatte (/dev/sdb) auftraten, wurde diese soeben im Rechenzentrum getauscht (ein Lob an Hetzner für den schnellen Support). Da die Platte Bestandteil eines Software RAID1-Verbunds ist, kurz die Schritte zum Entfernen und anschließenden Reaktivieren der Platte.
Zuerst alle Partitionen der Platte auf faulty setzen und anschließend aus dem jeweiligen Array entfernen:
mdadm /dev/md0 --set-faulty /dev/sdb1 mdadm /dev/md0 --remove /dev/sdb1 mdadm /dev/md1 --set-faulty /dev/sdb2 mdadm /dev/md1 --remove /dev/sdb2 mdadm /dev/md2 --set-faulty /dev/sdb6 mdadm /dev/md2 --remove /dev/sdb6
Nach dem Tausch der Platte muss zuerst die Partitionstabelle auf die neue Platte kopiert werden:
sfdisk -d /dev/sda | sfdisk /dev/sdb
Anschließend können die Partitionen wieder zu den jeweiligen Arrays hinzugefügt werden:
mdadm /dev/md0 --add /dev/sdb1 mdadm /dev/md1 --add /dev/sdb2 mdadm /dev/md2 --add /dev/sdb6
Über folgende Ausgaben kann der Resync der Arrays dann überprüft werden:
mdadm --detail /dev/md2 cat /proc/mdstat
VPN-Verbindungen mit VBS automatisiert erstellen
Da ich meine Rechner relativ oft neu aufsetze, ist es ziemlich nervig, jedes Mal diverse VPN-Verbindungen per Hand einrichten zu müssen. Deshalb hab ich eine Runde im Netz gesucht und bis auf ein VB-Script in einem Forumpost nicht viel gefunden. Da das Script aber tut, was es soll, habe ich es schnell auf ein deutsches Windows umgeschrieben und um die Möglichkeit mehrerer Verbindungen erweitert. Einfach das Connections-Array anpassen, als dateiname.vbs abspeichern und ausführen. Macht Spaß dabei zuzusehen ;)
Getestet unter Windows XP Pro, sollte aber auch unter Windows 2000 funktionieren. Keine Ahnung wie es unter Vista aussieht, wenn es jemand probiert wäre ein kurzes Feedback super.
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
Dim Connections
Connections = Array(Array("Verbindung 1", "127.0.0.1"), Array("Verbindung 2", "localhost"), Array("Verbindung 3", "192.168.1.1"))
With objShell
.Run "Control ncpa.cpl"
wscript.sleep 2000
End With
For i = 0 To UBound(Connections)
With objShell
.AppActivate "Netzwerkverbindungen"
wscript.sleep 500
.SendKeys "%DN"
wscript.sleep 500
.SendKeys "%W"
wscript.sleep 500
.SendKeys "%NW"
wscript.sleep 500
.SendKeys "%VW"
wscript.sleep 500
.SendKeys "%N" & Connections(i)(0) & "%W"
wscript.sleep 500
.SendKeys "%KW"
wscript.sleep 500
.SendKeys "%H" & Connections(i)(1) & "%W"
wscript.sleep 500
.SendKeys "{TAB}{TAB}{ENTER}"
wscript.sleep 500
.SendKeys "{ESC}"
wscript.sleep 500
End With
Next
Update: habe die Sleep-Zeiten auf 500ms erhöht, da ich teilweise Probleme hatte, wenn viele Verbindungen erstellt werden sollten.
Lazy Linux: 10 essential tricks for admins
Sehr interessanter Artikel von IBM, der einige nützliche Tipps&Tricks für den Linux Admin beschreibt.
Reinstall grub using a Linux Live-CD
I just reinstalled Windows on my dual-boot system and had to reinstall grub as Windows setup overwrites the existing master boot record. Here’s how I did it using a Linux Live-CD (im my case an Ubuntu 7.04 CD I had lying around). My Linux root partition is /dev/sda6.
First it’s necessary to mount our Linux filesystem (including /proc and /dev). If you got /boot on an extra partition, you have to mount that partition too.
root@ubuntu:~$ mkdir /mnt/root root@ubuntu:~$ mount -t ext3 /dev/sda6 /mnt/root root@ubuntu:~$ mount -t proc none /mnt/root/proc root@ubuntu:~$ mount -o bind /dev /mnt/root/dev
Then we can chroot into our system and re-install grub on /dev/sda.
root@ubuntu:~$ chroot /mnt/root /bin/bash root@ubuntu:~$ grub-install /dev/sda
Done.
Nützliche bash-Tastaturkürzel
Einige nützliche bash-Tastaturkürzel:
| Kürzel | Beschreibung |
|---|---|
| ALT+B, ALT+F | Cursor ein Wort zurück / weiter bewegen |
| CTRL+A, CTRL+E | Cursor an den Anfang / Ende der Zeile setzen |
| CTRL+K | Bis zum Ende der Zeile löschen |
| CTRL+T | Die vorigen beiden Zeichen vertauschen |
| ALT+T | Die vorigen beiden Wörter vertauschen |
| CTRL+L | Bildschirm löschen |
| CTRL+R, CTRL+S | Nach vorher eingegebenen Kommandos suchen |
Linux: mit Hintergrundprozessen arbeiten
Um auf der Shell einen Prozess in den Hintergrund zu senden gibt es 2 Möglichkeiten.
Den Prozess mit command & starten.
maff@mafftop:~$ vim & [1] 15564
Den Prozess mit CTRL+Z in den Hintergrund senden.
maff@mafftop:~$ vim <CTRL+Z> [1]+ Stopped vim
Um den Prozess wieder in den Vordergrund zu bekommen, reicht ein
maff@mafftop:~$ fg <job_nr>
Mit find und grep in Dateien suchen
Da ich morgen heute — in 4,5 h — Klausur über Operating Systems schreibe, ist heute Schnipseltag. Um die Zeichenkette “foo” in allen Dateien im aktuellen Verzeichnis zu finden und eine Liste dieser Dateien auszugeben bietet sich folgende Kombination aus find und grep an:
find . -type f -exec grep -qi "foo" {} \; -print
Und um bestimmte Verzeichnisse auszuschließen (z.B. .git):
find . -path '*.git' -prune -o -type f -exec grep -qi "foo" {} \; -print

I just discovered “Quickstart”, the swiss army knife for Ubuntu which is a handy little tool for different tasks. For more information see