rsync tips/tricks

Title:

rsync tips/trics

Author:

Douglas O’Leary <dkoleary@olearycomputers.com>

Description:

tips/tricks related to rsync

Disclaimer:

Standard: Use the information that follows at your own risk. If you screw up a system, don’t blame it on me…

Overview:

Every time I have to mess around with rsync - which is roughly every other year, I have to go hunt down the things I’ve done before either in client log files or on the web. Getting tired of that, so here’re the commands and processes for rsyng govno.

Details:

  • First, rsync’s going to be much easier with public key authentication. See ssh users’ guide for details on how to set that up.

  • Copy a directory structure. Obviously, either source or target can be remote:

    rsync -av --include='*/' --exclude='*' ${host}:/${dir} ${target_dir}
    
  • After that, it’s just a matter of looping through directories and/or mount points:

    for d in $(cat list-o-dirs)
    do
        Log=$(echo ${d} | sed 's/\//_/g')
        rsync -azv ${host}:${d}/ ${d} > ${Log}.log 2>&1
    done
    
  • One point: The source directory should have a trailing slash otherwise it’ll try making a subdirectory if it already exists. For instance: rsync -azv ${host}:/tmp /tmp will end up creating /tmp/tmp instead of copying all the files to /tmp. The trailing slash will prevent that. rsync -azv ${host}:/tmp/ /tmp