Hallo all and  wishing all a happy and prosperous new year

I have recently started to learn shell scripting and i am trying to write a backup script to backup my /home directory into external usb drive. I need suggestion on how to improve the script or to make it more concise.

the script is as follows:


#!/bin/bash
#checks if usb drive is present
if blkid |grep USB-Mass-Storage
then
#checks if user is logged in otherwise it may cause problem
if users|grep freedom
then
echo "user freedom is logged in" && exit 1 #if user is logged it exits 
immediately
else
#checks if destination folder exists
if [ -d /media/backup ]
then
#mounts the usb drive
/bin/mount LABEL=USB-Mass-Storage /media/backup
#begins logging
echo "------------------------------------------------------------------------- " 
>> /root/backup.log
#records the time of backup
echo $(date) >> /root/backup.log
echo "CONFIGURATION backup starting "|tee -a /root/backup.log
#begin /etc/ backup
/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 --delete-excluded --exclude-from=/root/exclude-pattern /var/ 
~freedom/backup/var/ >> /root/backup.log; echo "VARIABLE backup finished" |tee -a /root/backup.log
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
fi
else
echo "$(date)   USB drive not entered"|tee -a /root/backup.log
fi


Thank you for your suggestion.
_______________________________________________
Users mailing list
[email protected]
http://lists.dgplug.org/listinfo.cgi/users-dgplug.org

Reply via email to