rsync for migrating websites

Using rsync to migrate websites to new servers.

How to copy files to a remote server and keep symlinks in place, using rsync (instead of cp or scp)

Useful rsync switches

-v verbose
-q quiet
-a archive
-r recursive
-d directories without recursion
-g preserve group
-o preserve owner
-t preserve times
-z compress
-l copy links as symlinks
-e use ssh

and the most useful of all:
-n a dry run: show what will happen when you do run it

Copy from local machine to remote

rsync -v -e ssh /local/

So we will copy the local file /local/ over to the server using the username stuart and writing the files into /dir/on/remote.

Copy multiple files / directories

To copy multiple files or directories, simply list them space delimited :

rsync -avz /dir1 /dir3 /path/to/file3.txt[/code]

Will take dir1, dir2 and file3.txt over to the remote server and write them into /newlocation.

Rsync resursive

You can use -r for recursion, but if you are using -a (archive) is equivalent to doing -rlptgoD.

Leave a Reply

Your email address will not be published. Required fields are marked *