[CentOS] Beginner - need suggestion to improve BACKUP script
kira.laucas at gmail.com
Sat Dec 27 07:14:21 UTC 2008
I have recently started to learn shell scripting. Now
i am trying to write a script to backup /etc and /var to my home dir in
a separate folder and then backup the home dir to usb drive using rsync.
My goal is when i will run the script it will output status to standard
output in form of bold messages with time and simultaneously logs to
another file in /root dir. I have labled the usb drive as
"usb-mass-storage". the script runs fine according to my requirement.
Now i need suggestion to improve the script further. Thank you.
the script is as follows:
> if blkid |grep USB-Mass-Storage
> if [ -d /media/backup ]
> /bin/mount LABEL=USB-Mass-Storage /media/backup
> echo "------------------------------------------------------------------------- " >> /root/backup.log
> echo $(date) >> /root/backup.log
> /etc/rc.d/init.d/named stop &> /dev/null
> echo "CONFIGURATION backup starting "|tee -a /root/backup.log
> /usr/bin/rsync -a --progress --delete /etc/ ~freedom/backup/etc/ >> /root/backup.log;echo "CONFIGURATION backup finished" |tee -a /root/backup.log;echo "VARIABLE backup starting"|tee -a /root/backup.log;/usr/bin/rsync -a --progress --delete --exclude=ftp/pub/media/ /var/ ~freedom/backup/var/ >> /root/backup.log; echo "VARIABLE backup finished" |tee -a /root/backup.log;/etc/rc.d/init.d/named start&> /dev/null
> echo " Now we are going to backup $(date)" |tee -a /root/backup.log
> /usr/bin/rsync -a --progress --delete /home/freedom/ /media/backup/ |tee -a /root/backup.log; echo "BACKUP FINISHED $(date)" |tee -a /root/backup.log
> echo "$(date) DISTDIR does not exist" |tee -a /root/backup.log
> echo "$(date) USB drive not entered"|tee -a /root/backup.log
1>the /root/backup.log is the log file
2>i stop the named service before starting backup as i run the named
process in a chroooted environment and if i trey to manually backup
/var with rsync i get :/var/named/chroot/proc/kcore: <file> has vanished !
3>my home dir is /home/freedom
4>i exclude the /var/ftp/pub/media/ folder as it is just the copy of
centos 5 dvd which i use as my local base repo.
More information about the CentOS