Mirroring Script Using Rsync
  1. Install rsync on Debian/Ubuntu
    • aptitude install rsync
  2. Copy attached mirror script into /usr/local/bin
    • chmod +x /usr/local/bin/mirror

Different Mirroring Scripts for different purposes

  • 1. mirror script for backing up remote directory (using ssh)
    • following rysnc options are used:
      • -a, —archive archive mode; same as -rlptgoD (no -H, -A)
      • -v, —verbose increase verbosity
      • -H, —hard-links preserve hard links
      • -S, —sparse handle sparse files efficiently
      • -x, —one-file-system don't cross filesystem boundaries
      • -z, —compress compress file data during the transfer
      • —compress-level=NUM explicitly set compression level
#!/bin/bash
if [ $# = 0 ] ; then
    echo 'An rsync wrapper for mirroring. See rsync(1) for details.'
    echo "Usage: `basename $0` <source> <destination>"
    exit 1
fi
rsync -avHSxz --progress -e ssh "$@"
  • 2. mirror script for backing up local directory
    • without -e ssh argument, saves time on ssl encoding/decoding
    • without -z argument, saves time on compression/decompression
#!/bin/bash
if [ $# = 0 ] ; then
    echo 'An rsync wrapper for mirroring. See rsync(1) for details.'
    echo "Usage: `basename $0` <source> <destination>"
    exit 1
fi
rsync -avHSx --progress "$@"
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License