Cookie

Mirror a local directory with rsync

Published by TheJoe on

Estimated reading time: 2 minutes

Caution


This article was published more than a year ago, there may have been developments.
Please take this into account.

Today we talk about rsync: a command-line program that synchronizes a source with a local or remote destination. In today's example we will be synchronizing two local directories.

I recently offered my girlfriend a backup of her photos. I migrated my data to a local server and the external drive we use for backups has only its old data left. She suggests I take care of the backup because according to her she doesn't know how to do it.

Opening the disk it seems to me that recently he has never put his files in order and for example the photos although they are correctly cataloged, they are scattered among different directories. The most “populated” are Immagini (75GB) and Foto (188GB). The system he has adopted to catalog them follows more or less the same criterion, but there are duplicates in both directories so I decide they can be merged.

There are several ways to do this, but the best in my opinion is rsync. More or less valid alternatives may be unison or the most common cp, but I will not deal with that in this article.

Rsync is already installed on all major Linux distributions and its operation is very classic. By default it does not overwrite the content, but it just copies the files not present in the destination.

~# rsync -avh --progress ./Immagini/ /mnt/4TB/Foto/

-a is going to “archive” and recursively copies everything from source to destination while preserving all its characteristics (user, permissions, etc..)
-v gives verbose output and is going to “verbose”
-h shapes the output so that it can be intelligible and stands for “human readable”
--progress indicates the amount of work done as a percentage

Look here:  Copy files between two remote NAS via FTP

To have the missing files in the directory as well Immagini we just have to run the command again by inverting source and destination.

~# rsync -avh --progress /mnt/4TB/Foto/ ./Immagini/

In my case I was interested in having all the files in one destination, so I only launched it once, but I'm thinking of all the situations in which data redundancy is important and it is necessary to copy the same on different supports or in different places.


TheJoe

I keep this blog as a hobby by 2009. I am passionate about graphic, technology, software Open Source. Among my articles will be easy to find music, and some personal thoughts, but I prefer the direct line of the blog mainly to technology. For more information contact me.

0 Comments

Leave a Reply

Avatar placeholder

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.