what does this script do

I am having difficulty to understand what this line does in one of my backup scripts.

/usr/bin/rsync -av --delete /etc/passwd /etc/group /etc/ntp.conf /var/spool/cron /scripts/sysfiles>>/var/log/backup.log

This line is from this startTar function, which is used for zip all folders and backup them.

startTar ()

# This is the actual backup function. It uses tar to backup everything.

        ( echo "*****Start of Backup*****"
        /usr/bin/rsync -av --delete /etc/passwd /etc/group /etc/ntp.conf /var/spool/cron /scripts/sysfiles ) >> $bklog

  tar cvzT $bkInc -f $bkdisk/$host$d8t.tar.gz  >> $bklog 2>&1
  if [ $? != 0 ]; then
  mailIt $gis "Tar file create error on $host" "Could not create the tar file in scripts bksys.sh" $gis
  exit 1
  ( date
  echo "*****End of Backup*****" ) >> $bklog

Jason YuAsked:
Who is Participating?
Gerwin Jansen, EE MVETopic Advisor Commented:
THe line you mention is part of a combined command:

        /usr/bin/rsync -av --delete /etc/passwd /etc/group /etc/ntp.conf /var/spool/cron /scripts/sysfiles ) >> $bklog

is part of this:

 ( echo "*****Start of Backup*****"
        /usr/bin/rsync -av --delete /etc/passwd /etc/group /etc/ntp.conf /var/spool/cron /scripts/sysfiles ) >> $bklog

Note the ( ) - there are three commands in there:

echo ...
/usr/bin/rsync ...

output of these 3 commands is added to a file that is in the bklog variable.

That rsync command is copying (synchronizing) the set of files /etc/passwd /etc/group /etc/ntp.conf /var/spool/cron to the destination /scripts/sysfiles - which is a directory in your case, right? The /delete option means that if files exist in the destination that do not exist in the source, that they will be deleted.

Look at the bklog file to see what is happening:

tail -F $bklog

(you may have to use the bklog filename instead in case that bklog variable is only available in the script)
Seth SimmonsSr. Systems AdministratorCommented:
it is copying files to the destination...let's break it down

-a - used to copy files in archive mode
-v - verbose output
--delete - if a file listed in the source no longer exists, it will delete in the destination
/etc/passwd /etc/group /etc/ntp.conf /var/spool/cron - list of files and folders as the source
/scripts/sysfiles - the destination where the source is copied to
>>/var/log/backup.log - appends the output (where -v used above) to that log file
Jason YuAuthor Commented:
dear experts, thank you very much for quick reply. I will test this script after i finish my lunch.  Have a wonderful weekend.
Gerwin Jansen, EE MVETopic Advisor Commented:
Any feedback? Thanks.
Jason YuAuthor Commented:
I got it resolved, thank you.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.