Scott Robinson (quadhome) wrote,
Scott Robinson
quadhome

Bytebros and Bash Scripting!

More Bytebros work was done today. I locked down all the rounding issues in our reports and changed the data levels display. I’m waiting for Joe to contact me about some craziness in the pair length calculations.

For the low cost of 30 minutes of re-learning bash, I wrote a script that splits Tranzoa monthly backup trees into two DVD-Rs. It has sanity checking, runs in low memory and low hard drive environments, and is extremely simple to use:

scott@tara:~/rsync$ [0] ./burn.sh month-tree
...
Please insert Disk 2 and press and key to continue. [Enter]
...

I have no idea how I would have gotten this done in Windows.


scott@tara:~/rsync$ [0] cat burn.sh
#!/bin/sh

clean_temp_files ()
{
    # Clean up after ourselves.

    rm -f bsh.d1.path bsh.d2.path bsh.dall.path bsh.dmerge.path
    rm -f bsh.d1.pathlist bsh.d2.pathlist
}

# Generate the pathlists.

echo “$0: Generating pathlists...”

burndir=‘basename $1’

./d1-gen $burndir > bsh.d1.path
./d2-gen $burndir > bsh.d2.path
./dall-gen $burndir | sort > bsh.dall.path

# Sanity check to ensure all directories are obtain.

echo “$0: Performing pathlist sanity check.”

cat bsh.d1.path bsh.d2.path | sort > bsh.dmerge.path

if ! (diff -q bsh.dall.path bsh.dmerge.path); then
    echo “$0: Mismatched path lists. Aborting!”
    clean_temp_files
    exit
fi

# Print the sizes of both images.

echo “$0: Disk 1 (Most):” ‘cat bsh.d1.path | xargs du -Hsc | grep total’
echo “$0: Disk 2 (Biggies):” ‘cat bsh.d2.path | xargs du -Hsc | grep total’

# Process the pathlist files with grafts.

echo “$0: Generating graft lists...”

cat bsh.d1.path | xargs -i echo {}={} > bsh.d1.pathlist
cat bsh.d2.path | xargs -i echo {}={} > bsh.d2.pathlist

# Perform dry-runs to check it will all work.

echo “$0: Performing dry-runs...”

volid=‘date -f $burndir/date.txt +%F’
cddev=“/dev/hdd”
growcmd=“growisofs -dvd-compat -Z $cddev”
mkisofsopts=“-r -J -joliet-long -graft-points -q -V $volid”

if ! ($growcmd -dry-run ${mkisofsopts}-1 -path-list bsh.d1.pathlist); then
    echo “$0: Disk 1 dry-run failed. Aborting!”
    clean_temp_files
    exit
fi

if ! ($growcmd -dry-run ${mkisofsopts}-2 -path-list bsh.d2.pathlist); then
    echo “$0: Disk 2 dry-run failed. Aborting!”
    clean_temp_files
    exit
fi

# Start the burn cycle!

echo “$0: Starting burn cycle.”

if ! ($growcmd ${mkisofsopts}-1 -path-list bsh.d1.pathlist); then
    echo “$0: Disk 1 burn failed. Aborting!”
    clean_temp_files
    exit
fi

eject $cddev

read -p “Please insert Disk 2 and press any key to continue.”
if ! ($growcmd ${mkisofsopts}-2 -path-list bsh.d2.pathlist); then
    echo “$0: Disk 2 burn failed. Aborting!”
    clean_temp_files
    exit
fi

eject $cddev

clean_temp_files

scott@tara:~/rsync$ [0] cat d1-gen
#!/bin/sh

find $1 -maxdepth 2 \( \( -path “$1/backup/mozilla” -o -path “$1/backup/private” -o -path “$1/backup/tzpalm” \) -prune \) -o \( -path $1/backup -o -path “$1/backup/*” -prune -print \) -o \( -path “$1/*” -prune -print \)

scott@tara:~/rsync$ [0] cat d2-gen
#!/bin/sh

find $1 -maxdepth 2 \( -path “$1/backup/mozilla” -o -path “$1/backup/private” -o -path “$1/backup/tzpalm” \) -prune -a -print

scott@tara:~/rsync$ [0] cat dall-gen
#!/bin/sh

find $1 -maxdepth 2 \( -path $1/backup -o -path “$1/backup/*” -prune -print \) -o \( -path “$1/*” -prune -print \)

scott@tara:~/rsync$ [0]
Tags: pretentious
Subscribe
  • Post a new comment

    Error

    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 2 comments