rsync

From IndieWeb


rsync is a command line tool to copy files from one server to another, which can be used for incremental backups or migrating web hosts.

IndieWeb Examples

  • Aaron Parecki - I use rsync to back up all my web servers onto a backup server at home. A cron job runs nightly and rsyncs the entire "web" folder on all my servers
  • Tantek Γ‡elik - 2019-02-24…03-04 (starting at 2019/Austin) used rsync, specifically a command line similar to the example given, as a key part of a successful migration of all (10 of) my websites from one webhost to another.

Example Commands

The command below can be used to migrate a website from one host to another. This would be run on the host you are migrating from.

Doing it from the 'from' host (pushing) is better than from the 'to" host (pulling) because this avoids an errant temporary sshkey entry in the ~/.ssh/known_hosts file on your destination (new) host. (You could swap the order of the from and to paths if you wanted to run this on the new host and pull from the old host, but this is the reason not to do that.)

rsync -avz --delete --progress ~/aaronpk.com/public_html/ aaronpk@caldera.dreamhost.com:~/aaronpk.com/

Details

  • a - "archive mode" - enables rlptgoD, disables HAX
    • r - recurse into directories
    • l - copy symlinks as symlinks. without this, it would follow symlinks and copy the files, which can lead to duplicate data at the destination. however this can also cause missing data if there are symlinks at the source that are linked to things outside the folder you're copying.
    • p - preserve permissions of the files you're copying
    • t - preserve modification times
    • g - preserve group
    • o - preserve owner (only works if you are the superuser at the destination, otherwise has no effect)
    • D - preserve device files (only works for superuser), preserve special files
    • H - this option preserves hardlinks, so "a" disables it
    • A - this option preserves acls, so "a" disables it
    • X - this option preserves extended attributes, so "a" disables it
  • v - "verbose" shows each file that is copied
  • z - compresses data in transit, can significantly speed things up
  • --delete - removes any files at the destination that are not present in the source folder. Make sure you don't have anything at the destination you care about if you include this!
  • --progress - will report the progress as a percentage so that you can see how far along the copy is
  • public/ - The first path is where to copy from.
    • By including the trailing slash, this will copy the entire contents of this folder, including hidden files, which would not be included if you specified *.
    • The files will be created at the remote destination directly, the "public" folder will not be created at the destination.
  • aaronpk@caldera.dreamhost.com:~/aaronpk.com/ - The second path is where to copy to.
    • aaronpk@caldera.dreamhost.com - This should match however you SSH into your new server. username @ hostname
    • : - This is a separator between the SSH command and the path
    • ~/aaronpk.com/ - The tilde is the home directory, then specify the folder of the web root at the new host. Make sure to include the trailing slash in order to get the files to end up in the right spot

See Also