Learn how to a build a cloud-first strategyRegister Now


what does this script do

Posted on 2014-08-22
Medium Priority
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 bksys.sh" $gis
  exit 1
  ( date
  echo "*****End of Backup*****" ) >> $bklog

Question by:Jason Yu
  • 2
  • 2
LVL 36

Assisted Solution

by:Seth Simmons
Seth Simmons earned 1000 total points
ID: 40279455
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 38

Accepted Solution

Gerwin Jansen, EE MVE earned 1000 total points
ID: 40279706
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
ID: 40279717
dear experts, thank you very much for quick reply. I will test this script after i finish my lunch.  Have a wonderful weekend.
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40295857
Any feedback? Thanks.

Author Comment

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

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 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