Created
September 11, 2013 16:27
-
-
Save jmahmood/6526167 to your computer and use it in GitHub Desktop.
Data CD/DVD Backup script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# Wait for a CD to be inserted then copy the contents | |
# | |
echo "CD copy, press <ctrl>C to exit" | |
echo "Looking for disk..." | |
# | |
# Go into a continuous loop always looking for a new CD | |
while : | |
do | |
####### Get the mount point of /dev/sr0 out of the mounts file | |
TEST=$(grep /dev/sr0 /proc/self/mounts) | |
####### If it doesn't exist, loop until it does with 1 second pause | |
if [ "$TEST" == "" ]; then | |
echo -ne "." | |
sleep 1 | |
else | |
echo | |
############### Got it! Need to strip the mount point out of the string | |
TEST2=${TEST:9} | |
set $TEST2 | |
TEST=$1 | |
############### Do the copy process for the disk we found | |
echo $TEST | |
TEST=${TEST//\\040/ } | |
echo "Copying from $TEST" | |
mkdir -p ~/databackup/ | |
#rsync -vr --whole-file $TEST/* ~/cdbackup$TEST | |
rsync -rhW "$TEST"/* ~/databackup | |
chown -R jawaad:jawaad ~/databackup | |
chmod -R 2775 ~/databackup | |
############### Eject the CD with suitable pauses to avoid any buffer problems | |
sleep 1 | |
eject cdrom | |
sleep 2 | |
fi | |
######## Still looping! Go back and wait for another CD! | |
done | |
exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment