what does this script do

Posted on 2014-08-22
Last Modified: 2014-09-09
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" $gis
  exit 1
  ( date
  echo "*****End of Backup*****" ) >> $bklog

Question by:Jason Yu
    LVL 34

    Assisted Solution

    by:Seth Simmons
    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
    LVL 37

    Accepted Solution

    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)

    Author Comment

    by:Jason Yu
    dear experts, thank you very much for quick reply. I will test this script after i finish my lunch.  Have a wonderful weekend.
    LVL 37

    Expert Comment

    by:Gerwin Jansen
    Any feedback? Thanks.

    Author Comment

    by:Jason Yu
    I got it resolved, thank you.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
    How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now