Mirror a local directory with rsync
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
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.
0 Comments