How to Mirror A Directory Locally Using Rsync

Most of the instructions for mirroring a directory with Rsync involve mirroring the data to a different server. You can also use Rsync to sync or mirror a directory on the same computer as the source directory.

Here is an example command on how to mirror two directories locally. In this example, /home/apache/public_html is the source directory and /home/apache/public_html_bak is the destination directory. Forward slashes at the end of the directory names in the rsync command are important so don’t forget them. The sync is one-way in that the destination will mirror the source:

rsync -avr --delete --links /home/apache/public_html/ /home/apache/public_html_bak/

If you need to preserve ACLs and Extended attributes then you need to add the -A and -X switches:

rsync -avrAX --delete --links /home/apache/public_html/ /home/apache/public_html_bak/

If you want to just do a dry run to see what will happen when you run Rsync, then add the -n switch:

rsync -avrAXn --delete --links /home/apache/public_html/ /home/apache/public_html_bak/

Terminal