Administration
  Home arrow Administration arrow Page 4 - File Synchronization With Rsync
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
ADMINISTRATION

File Synchronization With Rsync
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 91
    2002-12-04


    Table of Contents:
  • File Synchronization With Rsync
  • Getting The Skinny
  • Building Blocks
  • Temporary Insanity
  • Remote Control
  • Doing More
  • What's In A Name?
  • Mirror, Mirror, On The Wall
  • Link Out

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    File Synchronization With Rsync - Temporary Insanity
    ( Page 4 of 9 )

    The first (and most basic) thing you can do with rsync involves using it as a more intelligent copy command on your local system. So, let's suppose that I have the following directory tree in my home area on my Linux box,
    [me@olympus] $ tree -d /home/me
    |-- Desktop
    |   |-- Autostart
    |   |-- Templates
    |   `-- Trash
    |-- bin
    |-- mail
    |-- public_html
    |   |-- cache
    |   `-- chatserver
    |       |-- chat
    |       |   |-- admin
    |       |   |-- config
    |       |   |-- images
    |       |   |   |-- admin
    |       |   |   |-- smilies
    |       |   |   `-- tutorials
    |       |   |-- install
    |       |   |   |-- database
    |       |   |   `-- languages
    |       |   |-- lib
    |       |   |   |-- commands
    |       |   |   `-- database
    |       |   `-- localization
    |       |       `-- english
    |       `-- docs
    |-- test
    `-- tmp
    
    27 directories
    and let's further suppose that I need to copy my personal Web pages to a backup folder ("/mnt/zip/backup") on the same system.
    [me@olympus] $ ls -l /mnt/zip/backup
    total 0
    With rsync, accomplishing this is a snap:
    [me@olympus] $ rsync --verbose --stats --recursive public_html
    /mnt/zip/backup/
    
    Number of files: 177
    Number of files transferred: 158
    Total file size: 1043209 bytes
    Total transferred file size: 1043209 bytes
    Literal data: 0 bytes
    Matched data: 1043209 bytes
    File list size: 3453
    Total bytes written: 15469
    Total bytes read: 12018
    As with a regular "cp" command, rsync needs to know the source and destination for the copy operation. Once it has this information, it compares the files in the two locations and updates the destination to an exact replica of the source. Let's see if it worked as advertised:
    [me@olympus] $ ls /mnt/zip/backup/
    public_html
    Yup, it did - as you can see, my backup folder now contains a copy of my Web pages.

    You can specify more than one source directory to be copied as well - let me add my "mail" directory to the list and run the command again.
    [me@olympus] $ rsync --verbose --stats --recursive public_html mail
    /mnt/zip/backup/
    
    Number of files: 181
    Number of files transferred: 161
    Total file size: 1043209 bytes
    Total transferred file size: 1043209 bytes
    Literal data: 0 bytes
    Matched data: 1043209 bytes
    File list size: 3513
    Total bytes written: 15637
    Total bytes read: 12066
    
    wrote 15637 bytes  read 12066 bytes  18468.67 bytes/sec
    total size is 1043209  speedup is 37.66
    Next, let's make a few changes to the original files, and see if rsync can detect them and selectively update the destination the next time I sync up.
    [me@olympus] $ touch public_html/a.dat
    [me@olympus] $ ls > public_html/a.dat
    [me@olympus] $ touch public_html/b.dat
    [me@olympus] $ rm public_html/cache/test.html
    [me@olympus] $ vi public_html/error.php
    As you can see, I've added a couple of new files, deleted one old file and made changes to one PHP script. Let's sync up again and see what happens.
    [me@olympus] $  rsync --verbose --stats --recursive public_html
    /mnt/zip/backup/
    Pretty cool, huh? rsync added the two extra files to my backup, and identified and copied the modified file as well. However, the single file I deleted from the source is still present in the backup - obviously, rsync didn't delete it.

    A quick look at the rsync documentation clears that one up - by default, rsync doesn't delete files from the destination when synchronizing directories. This default behaviour can be overridden by adding the "--delete" parameter to the rsync command line.
    [me@olympus] $ rsync --verbose --stats --recursive --delete public_html
    /mnt/zip/backup/
    And now my destination is an exact copy of my source.
    [me@olympus] $ ls /mnt/zip/backup/public_html/cache/
    
    index.php  m2_h.gif  m2_n.gif  tmp.gif
    It should be noted that the "--delete" option can cause substantial damage if used unwisely - the rsync manual suggests always performing a dry run first when using this option.

     
     
    >>> More Administration Articles          >>> More By icarus, (c) Melonfire
     

       

    ADMINISTRATION ARTICLES

    - Network Booting via PXE: the Basics
    - Scalix: Linux Administrator`s Guide
    - Network Administration with FreeBSD 7
    - Components of an Information Architecture
    - The Anatomy of an Information Architecture
    - Configuring Load-Balanced Clusters
    - Load-Balanced Clusters
    - UNIX Time Format Demystified
    - Making Changes in the CVS
    - Building Your First CVS Repository
    - CVS Quickstart Guide
    - Authorizing Users in Samba
    - Handling User Accounts in Samba
    - Authentication in Samba
    - Accounts, Authentication, and Authorization





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek