Linux has a wide range of applications to perform backups, some of them very powerful. In this howto, I’m going to introduce you to rsync, a powerful yet simple command line application. With rsync we can perform exact copies of directories, partitions or whatever, mantaining the file permissions, soft links, and all. So, you have an exact copy. Running rsync daily allows us to mantain a synchronized copy of a partition to an external hard drive. If something wrong happens, we will have the latest copy of that partition saved in an external device. In my case, I always have an exact synchronized copy of my /home directory. If I have to upgrade my OS, I install the latest OS and then just copy the files to my /home directory without losing permissions, obviously if I mantain the same username.
Backing up with rsync
Type:
rsync -av – -stats /sourcedirectory /targetdirectory
With this command, I’ll have an exact copy of sourcedirectory in targetdirectory. Take into account if you delete some file in sourcedirectory and it has been backed up previously it will not be deletec in the targetdirectory in future backups. To delete it, just type:
rsync -av – -delete – -stats /sourcedirectory /targetdirectory
If you want to exclude a directory from being backed up, then use the – -exclude command like follows:
rsync -av – -exclude=directorytoexclude – -delete – -stats /sourcedirectory /targetdirectory
where directorytoexclude is the directory’s name. It is not necessary to be the whole path.
July 30, 2006 at 9:38 am |
Gracias! Very useful and fast.
September 9, 2006 at 6:24 pm |
Hola Jordi!
Desgraciadament no functiona per me:
eamann@eamann-laptop:~$ rsync -av – -stats /home /lacie
rsync: -: unknown option
rsync error: syntax or usage error (code 1) at main.c(1108)
(Fa mults anys vaig pasar una temporada a Barcelona i vaig apprendre una mica de catala.)
I’m a newbie and perhaps I haven’t given the proper address for the directories?
Eamann
September 10, 2006 at 7:35 pm |
Hi Eamann,
There must be a space between stats and sourcedirectory, i.e. rsync -av –stats /source /target (all with spaces in between the commands)
September 10, 2006 at 7:37 pm |
In the last post of mine is – -stats. I don’t know why it’s typed wrong when you write two dashes