I’m doing a a backup script to tar & gzip files from a FreeBSD server, transfer the .gz file to my mac and then write a CD.
The script is as shown below. I have several problems. Sometimes the script stops with a “Conection is invalid” I’m not sure where this occurs (generally after file is trf’d to mac. Possibly a problem with the umount command?
The other problem is that I have difficutly in checking that the ‘backup’ script in the terminal window is finished before starting copying to CD. I’ve had to use an inelligant clear and check to see what the screen says - hence the large blank space. Obviously if a user changes the terminal window size it never works.
Any ideas on improvements or proper error control? Also info on using HDIUTIL to auto burn the CD?
Any help greatly appreciated.
Geoff
The backup script (‘backup’) is:
BACKUPSCRIPT
#!/bin/sh
#Backup Script: For Tarring/Gzipping a directory on the local server and moving to a remote server for storage.
#Secure Copy/SMB/FTP
#Nick Mitchell (nick@delaware.net)
#Variables are Assigned Here
backupdir=“/usr/opera/” #The Directory You Wish to Backup (ex. /root/important/data/)
remserver=“192.168.1.4” #Server to move Backups too. (ex. backup-server.delaware.net)
remotedir=“//public/backup” #Remote Directory on Backup Server. (ex. /home/backup/)
localmnt=“/usr/operabackup/” #Local Mount Point For Samba
compressprog=“gzip -rv” #Compression Software with appropriate flags. (ex. gzip -9)
archiveprog=“tar -cf” #Archive Software with appropriate flags. (ex. tar -cpvf)
archivename=“backup.tar” #Archive File Name
remotetype=“smb” #Options: scp=Secure Copy, smb=Samba, ftp=File Transfer Protocol
remoteuser=“geoffwilliams” #Remote System Username
remotepass=“xxxxx” #Remote System Password
securecp=“/usr/bin/scp” #Secure Copy Location
log=“backup.log” #Log Errors and Info to this file
email="geoff@192.168.1.4" #Who to send logs too…
##############################Do Not Edit Please###############################################
#Cleanup From Last Run
rm -rf $log
#Test to see if backup directory exists.
echo -e "Checking Backup Directory to see if it exists.n " >> $log 2>&1
if [ -d $backupdir ];
then
#Start archiving files
$archiveprog $archivename $backupdir >> $log 2>&1
#Start to compress tar file
$compressprog $archivename >> $log 2>&1
#Convert Filename from tar to tar.gz
archivename=$archivename.gz
#Decide Which Remote Access Type We are Using
if [ “$remotetype” = “smb” ]; then
mkdir -p $localmnt
#mount -t smbfs -o username=$remoteuser,password=$remotepass,ip=$remserver $remotedir $localmnt >> $log 2>&1
mount_smbfs -I 192.168.1.4 //geoffwilliams@g4samba/public /usr/home/geoff/smb
#Move to Backup Server
cp -pv $archivename $localmnt >> $log 2>&1
#Tell Everyone that it worked out for the better
echo -e "n "
echo -e “My Work Here is Done $backupdir has been backed up to $remservern” >> $log 2>&1
#Send an Email as a Follow Up
#mail $email -s “Backup Completed” < $log
#Cleanup
umount $localmnt >> $log 2>&1
rm -rf $archivename >> $log 2>&1
rm -rf $log >> $log 2>&1
else echo -e "Backup Directory Not Found or Is Not A Directoryn "
fi
##############################Do Not Edit Please###############################################
APPLSCRIPT
tell application “Terminal”
set ScriptCommand to "ssh -X " & “colin” & “@” & “192.168.1.100”
say “logging on to FreeBSD Server”
activate
do script ScriptCommand in window 1 – Establish the SSH connection
delay 3 – Wait 3 seconds for the password prompt to appear
do script “XXXXXX” in window 1
delay 2
do script “su” in window 1
say “changing to root user”
delay 2
do script “XXXXXX” in window 1
delay 3
do script “clear” in window 1
delay 2
do script “sh backup” in window 1
say “doing script and compressing files”
set theIndicator to contents of window 1
repeat until theIndicator = "samba# sh backup
samba#
"
delay 2
print theIndicator
set theIndicator to contents of window 1
end repeat
beep
say “done the compressing of the files - now exiting”
do script “exit” in window 1
delay 2
do script “exit” in window 1
delay 2
do script “exit” in window 1
delay 2
close window 1
quit
end tell
tell application “Finder”
set x to 1
repeat until disk “Untitled CD” exists
delay x
say "Put a blank CD in the drive "
activate
set x to x + 1
end repeat
say "Now Copying backup file - please wait"
end tell
tell application “Finder”
activate
–make new Finder window to disk “Untitled CD”
–set position of Finder window 1 to {606, 461}
with timeout of 240 seconds
say " now copying file to cd"
copyFile “Macintosh HD:Users:geoffwilliams:OperagzCD:opera.gz” to “Untitled CD:opera.gz”
–close window “Untitled CD”
end timeout
set thedate to current date --using scripting addition command
–result: date “Saturday, February 27, 1999 3:37:50 PM”
weekday of thedate --result: Saturday
day of thedate --result: 27
month of thedate --result: February
year of thedate --result: 1999
time of thedate --result: 56270 (seconds since 12:00:00 AM)
time string of thedate --result: “3:37:50 PM”
date string of thedate --result: “Saturday, February 27, 1999”
say “Changing the CD name to today’s date”
set name of disk “Untitled CD” to date string of thedate
say "Now drag CD to trash and Burn - Thank you"
display dialog "Now drag CD to trash and burn"
end tell