Results 1 to 1 of 1
I've been spending time on a Debain (Etch) system learning Apache, Trac, Subversion, PHP, and the like. I'm trying to increase my proficiency at the command line so I wrote ...
- 05-21-2008 #1Just Joined!
- Join Date
- Nov 2006
- Posts
- 4
My first bash script - less than elegant
I've been spending time on a Debain (Etch) system learning Apache, Trac, Subversion, PHP, and the like. I'm trying to increase my proficiency at the command line so I wrote my first backup script. I'm simply looking for some feedback on better ways of doing things. This one just backs up my trac environment.
#! /bin/bash
#blow away the previous hot copy directory or it will error out
#hotcopy will not overwrite anything
rm -rf /backup/trac/
if [[ $? -eq 0 ]]
then
# make sure our directory path exists
mkdir -p /backup/trac/
else
mailx -s "Backup Failed: tried to remove files under /backup/trac" mymail@yahoo.com </home/parker/bin/trac_email_body
exit 1
fi
if [[ $? -eq 0 ]]
then
# issue hotcopy command
trac-admin /srv/trac/mysite.com hotcopy /backup/trac/mysite.com.trac
else
mailx -s "Backup Failed: tried to make dir /backup/trac/" mymail@yahoo.com </home/parker/bin/failure_template
fi
if [[ $? -eq 0 ]]
then
# tar all the files together
tar -cf /backup/trac/mysite.com.trac.tar /backup/trac/mysite.com.trac/
else
mailx -s "Backup failed: hotcopy mysite.com" mymail@yahoo.com </home/parker/bin/failure_template
exit 1
fi
if [[ $? -eq 0 ]]
then
#compress the tar we just created
bzip2 -z /backup/trac/mysite.com.trac.tar
else
mailx -s "Backup failed: could not tar mysite.com" mymail@yahoo.com </home/parker/bin/failure_template
exit 1
fi
if [[ $? -eq 0 ]]
then
#move our compressed file to a backup location
mv /backup/trac/mysite.com.trac.tar.bz2 /home/usb_500/backup/linux_dump/mysite.com.trac.tar.bz2
else
mailx -s "Backup failed: could not compress mysite.com.tar" mymail@yahoo.com </home/parker/bin/failure_template
exit 1
fi
if [[ $? -eq 0 ]]
then
#send an email to myself alerting me that everything went okay
mailx -s "Trac Backup Executed" mymail@yahoo.com </home/parker/bin/trac_email_body
else
mailx -s "Backup Failed: tried to move file to windows share" mymail@yahoo.com </home/parker/bin/trac_email_body
fi


Reply With Quote