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

[code]
-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
[/code]

Copy from local machine to remote

[code]
rsync -v -e ssh /local/file.zip stuart@theremoteserver.net:/dir/on/remote
[/code]

So we will copy the local file /local/file.zip over to the server theremoteserver.net 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 :

[code]
rsync -avz /dir1 /dir3 /path/to/file3.txt stuart@theremoteserver.net:/newlocation/[/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.




No Comments


No comments yet.



Leave a Reply

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