Unix Tip: Experimenting with rsync

January 23, 2008, 12:42 PM —  ITworld.com — 

Given the comments and questions I've received since last week's column on using rsync to move a file system from one disk to another, I thought we might run through some simple exercises to gain more insight into how rsync works. Two of the problems that I have seen people running into when using rsync to copy collections of files from one place to another are 1) failing to retain symbolic and hard links and 2) misaligning the source and destination directories such that the copies don't look as intended. Here we'll create a directory with a number of files, copy the directory with an assortment of rsync (and other) commands, take a closer look at some of rsync's command options and then use rsync to verify that our replicated directory is intact.

First, to create a sample directory to be copied, we're going to use a smattering of common Unix commands, taking care to include a variety of file types.

testDir=" rsyncTest"
mkdir $testDir
touch $testDir/emptyfile
cp /etc/motd $testDir/textfile
mkdir $testDir/dir
mknod $testDir/devfile c 11 11
ln -s /etc/hosts $testDir/symlink
ln $testDir/textfile $testDir/link2textfile

In the commands above, we've created a small directory containing some regular files (one empty, one containing text), a directory, a special device file, a symbolic link and a hard link. A long listing displays the directory's contents. Notice that I've included the -i option so that I can see the inode used for each of the files.

> ls -li $testDir
total 8
   7865105 crw-r--r--   1 root     other     11, 11 Jan 22 12:01 devfile
   7865103 drwxr-xr-x   2 root     other        512 Jan 22 12:01 dir
   7865089 -rw-r--r--   1 root     other          0 Jan 22 12:01 emptyfile
   7865090 -rw-r--r--   2 root     other        233 Jan 22 12:01 link2textfile
   7865107 lrwxrwxrwx   1 root     other         10 Jan 22 12:01 symlink -> /etc/hosts
   7865090 -rw-r--r--   2 root     other        233 Jan 22 12:01 textfile

Sign up for ITworld's Daily newsletter
Follow ITworld on Twitter @IT_world

I like it!
Close

On Twitter now

Unix

Powered by Twitter
You are logged in | Sign out
Sign in and post to Twitter

What are you thinking?

Cancel Tweet sent

On Twitter now

Post a comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
peer-to-peer

Esther Schindler
If the comments are ugly, the code is ugly

claird
SVG a graphics format for 21st century

pasmith
Take Chrome OS for a test spin

Sandra Henry-Stocker
Solaris Tip: Have Your Files Changed Since Installation?

sjvn
64-bits of protection?

jfruh
Android fragments vs. the iPhone monolith

mikelgan
What Gizmodo missed about the Pro WX Wireless USB disk drive

 

Where Google Chrome security fails: the password
I heard mention that the Chrome OS will have some sort of encryption available a la bitlocker. If it's possible to encrypt personal data using another password or key, then it may have potential for very secure data.... And Ubuntu has an 'encrypt home directory' option, perhaps google should follow suit.
- Dann

Join the conversation here

The Daily Tip

The Daily TipQuick, practical advice for IT pros. Made fresh daily.

Hot tips:

Want to cash in on your IT savvy? Send your tip to tips@itworld.com. If we post it, we'll send you a $25 Amazon e-gift card.

Newsletters

Subscribe to ITWORLD TODAY and receive the latest IT news and analysis.

I would like to receive offers via email from ITworld partners.
By clicking submit you agree to the terms and conditions outlined in ITworld's privacy policy.
Featured Sponsor

AISO founders envisioned a Web hosting company that was environmentally friendly. While the company employed energy-efficient innovations like solar panels, its infrastructure produced unacceptable power and cooling requirements. Find out how AISO leveraged AMD technology to overcome their challenge in this case study white paper.

In this whitepaper, Scalar explores the opportunity to change the landscape with respect to mission critical databases built around Oracle. Leveraging technologies such as Linux, high-end commodity processing power and Oracle RAC technology to architect, design, build and maintain database infrastructure that delivers maximum availability, reliability and performance at a fraction of traditional cost.

On a typical day, weather.com, the Web site for The Weather Channel in Atlanta, serves up between 15 million and 20 million page views. But in September 2004, when back-to-back hurricanes ransacked Florida, the peak traffic on one day more than tripled: over 70 million page views by more than 7 million unique visitors. Read the full success story now.

Marketplace