hallo list,
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:
#!/bin/sh if blkid |grep USB-Mass-Storage then if [ -d /media/backup ] then /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 else echo "$(date) DISTDIR does not exist" |tee -a /root/backup.log fi else echo "$(date) USB drive not entered"|tee -a /root/backup.log fi
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.
On Sat, Dec 27, 2008 at 12:44:21PM +0530, partha chowdhury wrote:
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 !
Always exclude /var/named/chroot/proc/ from your backups. backing it up isn't needed. See: https://www.linuxquestions.org/questions/linux-general-1/prockcore-what-is-i...
Jeff Kinz
--
jkinz@kinz.org wrote:
On Sat, Dec 27, 2008 at 12:44:21PM +0530, partha chowdhury wrote:
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 !
Always exclude /var/named/chroot/proc/ from your backups. backing it up isn't needed. See: https://www.linuxquestions.org/questions/linux-general-1/prockcore-what-is-i...
Jeff Kinz
Thank you for the suggestion !
so now i backup /var/ with the follwing command:
rsync -a --progress --delete --delete-excluded --exclude-from=/root/exclude-pattern /var/ ~freedom/backup/var/
it seems fine as no error message is generated but is there any more efficient alternative ?
Partha chowdhury wrote on Sat, 27 Dec 2008 12:44:21 +0530:
the script is as follows:
Next time put this in original format on a website, spares download bandwidth for those that don't want to see it and aching eyes for those that want to see it.
Kai
Kai Schaetzl wrote:
Partha chowdhury wrote on Sat, 27 Dec 2008 12:44:21 +0530:
the script is as follows:
Next time put this in original format on a website, spares download bandwidth for those that don't want to see it and aching eyes for those that want to see it.
Kai
i at first thought of sending as an attachment but then i read sending attachment to a mailing list is a bad idea. so i just pasted it. now i know to use pastebin.centos.org.
i have added to check for logged in user whose home directory to be backed up in case there are open files by processes owned by that user.
how can i make it more concise ?