Administration
  Home arrow Administration arrow Page 4 - File Synchronization With Rsync
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
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? 
ADMINISTRATION

File Synchronization With Rsync
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 81
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Dell PowerEdge Servers

    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: 177Number of files transferred: 158Total file size: 1043209 bytesTotal transferred file size: 1043209 bytesLiteral data: 0 bytesMatched data: 1043209 bytesFile list size: 3453Total bytes written: 15469Total 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: 181Number of files transferred: 161Total file size: 1043209 bytesTotal transferred file size: 1043209 bytesLiteral data: 0 bytesMatched data: 1043209 bytesFile list size: 3513Total bytes written: 15637Total bytes read: 12066wrote 15637 bytes read 12066 bytes 18468.67 bytes/sectotal 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

    - 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
    - Advanced Concepts on Dealing with Files and ...
    - Dealing with Files and Filesystems
    - More Hacks for the User Environment in BSD
    - Personalizing the User Environment in BSD
    - Customizing the User Environment in BSD

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway