Login
Newsletter
Werbung

So, 21. April 2002, 00:00

Datenbackup auf CD-RW

Vorwort

Die Sicherung der Daten ist von zentraler Bedeutung, wenn es darum geht, seine Daten vor Verlust zu schützen. Besonders für den privaten Anwender, der so wenig Zeit wie möglich mit administrativen Aufgaben verbringen will, ist es also wichtig, eine einfache und zuverlässige Lösung zur Hand zu haben.

Die meisten Rechner sind heute mit einem CD-Brenner ausgestattet. Warum also nicht diesen Brenner, mit wiederbeschreibbaren Medien bestückt, zur Datensicherung verwenden? Da das traditionelle GNU Tool "tar" solche Laufwerke nicht ohne weiteres unterstützt, möchte ich in diesem Artikel ein Shellskript von meinem Kollegen Jörg Hau vorstellen, das es ermöglicht, mit einem einzigen Aufruf mehrere Verzeichnisse, z.B. das gesamte /home, auf eine CD-RW zu brennen.

Funktionen und Einschränkungen

Vorteile:

  • Einfach zu konfigurieren durch editieren einiger weniger Variablen am Anfang des Skriptes.
  • Erzeugt eine direkt lesbare CD: keine besonderen Tools zur Wiederherstellung der Daten erforderlich.
  • Prüft, ob die Datenmenge auf die CD paßt.
  • Erhält Verzeichnisstrukturen und Zugriffsrechte - auch Schreibrechte.

Nachteile:

  • Datenmenge ist auf eine CD (ca. 650 MB) beschränkt.
  • Derzeit noch keine Integritätskontrolle der gesicherten Daten (siehe unten).

Für das erste Problem gibt es ein anderes Skript mit Namen cdtape vom selben Autor; Anmerkungen zum zweiten Problem siehe unten.

saveset - Listing

#! /bin/sh
# 'saveset'
#
# - writes data to CD-RW for backup
# - allows to specify directories & exclude patterns
# - supports only 1 CD
#
# TO DO: - check that mkisofs is 1.13 or later
#	 - check integrity of CD image after burning
# -----------------------------------------------------------------
# Note 1: adjust parameters, CD-RW device etc. below!
# Note 2: This must be run as root.
# -----------------------------------------------------------------
# Creation: 2001-10-03, JHa (first "draft").
# Revisions:
# 2001-10-05, JHa: added check fpor free space, set preservation
# of correct file permissions (Thanks to Hendric Stattman!)
# 2001-10-28, JHa: excluded wwwoffle completely
# 2001-11-03, JHa: adjusted for mkisofs-1.14 syntax
# -----------------------------------------------------------------
# Copyright (c) 2001 Joerg Hau <joerg.hau(at)dplanet.ch>.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version, provided that
# the copyright notice remains intact even in future versions.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# -----------------------------------------------------------------
# disable filename expansion
#
set -f
# the CD-RW device & speed, 'cdrecord' syntax (dev=BUS,ID,LUN)
#
WRITE_DEV="dev=0,6,0"
WRITE_SPEED="speed=4"
# Blanking option:
# for CD-RW media, specify "blank=fast". For CD-R, set it to "".
#
BLANK="blank=fast"
# the temporary file
#
IMG="/tmp/img.iso"
# list of directories to archive. DO NOT use slashes!
#
DIRLIST="home root etc var"
# ... and list of exclude pattern (see mkisofs manpage)
#
EXCLUDE="*cache* *~"
# name for the Volume
#
NAME="Celeron"
#
# --- off we go ...
#
if [ `whoami` != 'root' ]
then
 echo "You must be root to run this script."
 exit 2
fi
# concatenate list of directories & excludes
#
DIRS=`for X in $DIRLIST; do echo -n "$X/=/$X "; done`
EXCL=`for X in $EXCLUDE; do echo -n "-m "$X" "; done`
echo -n "Preparing to archive ("
for X in $DIRLIST; do echo -n " $X"; done
echo " )"
echo "Excluding ( "$EXCLUDE" )"
# get size from a "dry run", same parameters as for the final run below
#
# for mkisofs 1.13:
#
# SIZE=`/usr/bin/mkisofs -J -L -R -V $NAME -quiet -o $IMG $EXCL \
# -print-size -graft-points $DIRS 2>&1 \
# | grep "scheduled to be written" | cut -d ' ' -f 8`
#
# for mkisofs 1.14:
#
SIZE=`/usr/bin/mkisofs -J -L -R -V $NAME -quiet -o $IMG $EXCL \
-print-size -graft-points $DIRS`
# For 650-MB CD media, don't let the image file to grow bigger than
# 332500 blocks (each 2048 bytes, makes 680960000 bytes in total).
# Some CD-writing programs and/or CD-R disks don't allow bigger images.
#
echo "Size of ISO image is $SIZE blocks."
if (($SIZE > 332500)); then
	echo "Sorry, this is too big - should be less than 332500 blocks."
 	exit 1
fi
# verify that we have enough disk space in $IMG
# FIXME: this is not very "clean" as we rely on "img.iso"
# as last part of the filename.
#
IMGDIR=`echo /tmp/img.iso | sed s/'img.iso'/' '/`
FREE=`df --block-size 2048 $IMGDIR | grep dev | awk '{print $4}'`
if (($FREE < $SIZE)); then
	echo "Sorry - not enough disk space to store image file."
	exit 1
fi
# arrive here if OK: Create a "real" image file,
# burn to disk and erase image file afterwards.
# Option '-R' preserves file permissions.
#
/usr/bin/mkisofs -L -J -R -V $NAME -quiet \
 -o $IMG $EXCL -graft-points $DIRS \
&& cdrecord -v $WRITE_DEV $WRITE_SPEED $BLANK -eject $IMG \
&& rm $IMG && return="0"
# FIXME: check for integrity of data
# mount -t iso9660 -o ro /cdrom
# for X in $DIRLIST; do diff -r /$X /cdrom/$X"; done
# ... all we need to implement here is an error check for diff
# and ... well, the consideration of the exclude list ;-)
#
# set an exit status.
test "$return" = "0" || exit 1
exit 0

Kommentare (Insgesamt: 0 )
Pro-Linux
Pro-Linux @Facebook
Neue Nachrichten
Werbung