Next Previous Contents

16. Appendix B - path-list.sh

This is shell script to do backup on CDROM and is used in the chapter Quick Steps of this document.


#!/bin/sh

# Author: Al Dev  EMail: alavoor@yahoo.com
# Copyright Al Dev, License : GNU/GPL
# Filename: path-list.sh

# Program to back a large partition > 650 MB over 
# several cdrom blanks by splitting into chunks.
# This program will create a list of filenames which can be input
# to mkisofs command's -path-list option. See 'man mkisofs'.

DIRNAME=""
while :
do
        if [ "$DIRNAME" != "" ];  then
                if [ ! -d $DIRNAME ]; then
                        echo "******"
                        echo "****** Wrong entry: Directory does not exist. Try again"
                        echo "******"
                else
                        break;
                fi
        fi
        echo " "
        echo "Please enter the directory name which you want to"
        echo "backup to multiple cdrom blanks."
        echo "Also make sure you have write/read permissions in that directory."
        echo "Enter with leading slash, for example, "
        echo -n "something like /backups/usr-partition : "
        read DIRNAME
done

OUTFILE="path-list.txt"

# Serious problems is - mkisofs complains and gives errors on
# directories and links (because of duplicate listing).
# Hence, soft/hard links need to be removed when doing mkisofs command
# Work around for soft links: Tar all the soft links to
# a file called Softlinks.tgz and then backup this file
tar zcvf $DIRNAME/Softlinks.tgz ` find $DIRNAME -type l `

if [ ! -f $DIRNAME/Softlinks.tgz ]; then
        echo " "
        echo "****************************************************************"
        echo "FATAL ERROR: Enable to create the file $DIRNAME/Softlinks.tgz"
        echo "May be you do not have read/write permissions in $DIRNAME"
        echo "****************************************************************"
        echo " "
        exit
fi

# Avoid directories and links

find $DIRNAME -type f -printf "%s %p\n" > $OUTFILE
find $DIRNAME -type b -printf "%s %p\n"  >> $OUTFILE
find $DIRNAME -type c -printf "%s %p\n"  >> $OUTFILE
find $DIRNAME -type p -printf "%s %p\n"  >> $OUTFILE
find $DIRNAME -type s -printf "%s %p\n"  >> $OUTFILE

TOTALSIZE=0
FILECOUNTER=1
rm -f CDROM-BACKUP*.txt
rm -f "CDROM-BACKUP"$FILECOUNTER".txt"

cat "$OUTFILE" |
while read LINE
do
        SIZE=`echo $LINE | cut -d' ' -f1 `
        #echo SIZE $SIZE
        FILENAME=`echo $LINE | cut -d' ' -f2 `
        TOTALSIZE=$(( $SIZE + $TOTALSIZE ))
        #echo TOTALSIZE $TOTALSIZE

        # If greater than 650 MB then switch to new group file
        # Do upto 649 MB = 649 * 1024 * 1024 = 680525824
        if [ $TOTALSIZE -gt 680525824 ]; then
                FILECOUNTER=$(( $FILECOUNTER + 1 ))
                TOTALSIZE=0
                rm -f "CDROM-BACKUP"$FILECOUNTER".txt"
        fi
        echo $FILENAME >> "CDROM-BACKUP"$FILECOUNTER".txt"
        #echo $FILENAME 
done

rm "$OUTFILE"

echo " "
echo "********************************* "
echo " Load a new CDROM blank and do :
nice --20 mkisofs -R -path-list CDROM-BACKUP1.txt | cdrecord -v fs=40m speed=2 dev=0,0 - 
Load next CDROM blank
nice --20 mkisofs -R -path-list CDROM-BACKUP2.txt | cdrecord -v fs=40m speed=2 dev=0,0 - 
Load next CDROM blank
nice --20 mkisofs -R -path-list CDROM-BACKUP3.txt | cdrecord -v fs=40m speed=2 dev=0,0 - "
echo "********************************* "


Next Previous Contents