Digital Media Insights for Business Owners

The easy tutorial of Rsync to “SYNC” two folders and its contents.

If you are looking for a solution to syncing two folders, whether it’s over a network or locally, this is how you do it.

In my opinion this is very valuable as a backup solution, specially when you have media files that are very important to you and you  don’t want to lose them.

The rSync Solution

The -a flag means “archive” which in turn means recursive and preserving symbolic links, ownership and permissions. In general, it is more likely to use -a than to use -r (recursive).

				
					rsync -a sourceDir/ destinDir
				
			

Before you make a sync, sometimes it is valuable to know what would happen before you actually do it. We call this: dry-run.

The -n variable is meant as a test “dry-run” and so no actual changes are made. -v is Verbose.

				
					rsync -anv sourceDir/ destinDir
				
			

Now, if you are doing the rsync through a network you also want to compress the data so that it happens faster. The -z flag compresses the network transfer reducing the size of the transfer as much as possible. The -P flag combines –progress (progress bar) and –partial (to resume interrupted transfers).

				
					rsync -azP sourceDir/ destinDir
				
			

The –delete flag deletes the files in the destination that have been removed in the source. Therefore keeping a true sync between both directories. Ideally run it with -nv flag first to make sure that is to be removed is what you want.

				
					rsync --delete sourceDir/ destinDir
				
			

Summary

So in summary you want to use this to Sync two directories:

1. Run it as a test.

				
					rsync -anv sourceDir/ destinationDir
				
			

2. Ready? Run it.

				
					rsync -azPv sourceDir/ destinationDir
				
			

3. If the sync has been there before, and so now is truly about syncing the two directories then use:

				
					rsync -azPv --delete sourceDir/ destinationDir
				
			

Note: If you use a slash at the end of the first directory, then it means: “The contents of sourceDirectory” but not the directory itself. On the other hand if you ommit the use of the slash in the sourceDirectory then it means: “The content of the sourceDirectory but also the SourceDirectory/ itself”.

Finally, you can change the order of the arguments to make it more memorable. Instead of -azPv you can do -Pazv –delete

Paz is the word for peace in Spanish, and so you’ll remember easy that you want a peaceful rsync. Paz –delete.

				
					rsync -Paz --delete sourceDir/ destinationDir
				
			

Say: "Hola" to your new clients.

Follow us on Social Media for more Tips & Tricks.

Other Posts You May Enjoy