I need to backup my Linux home directory to one of my portable hard disk. I tried to use git, but failed since git doesn’t support large file (I failed after many tries, I have file larger than 5G). I find rsync, the fast, versatile, remote (and local) file-copying tool and I am happy with it now. rsync is very fast especially the change is incremental. rsync can generate a delta of the change.
The method is simple, just execute this command:
$ rsync -avxP \ /path/to/directory/to/backup \ /path/to/directory/for/storing/backup
-a means archive mode -v means print out the verbose information during backuping -x means not cross filesystem boundaries -P is shortcut for --progress means printing information showing the progress of the transfer --partial means keeping partially transferred files if the transfer is interrupted
Note that the files on the destination directory storing the backup data will be kept if the files do not exist in the source directory to be backup’ed. If you would like `rsync` to delete the files/directories in the destination directory if the files/directories does not exist in the source directory, you can add `–delete` to `rsync`:
$ rsync -avxP --delete \ /path/to/directory/to/backup \ /path/to/directory/for/storing/backup
You can check all options of rsync from [[man:1|rsync|rsync’s man page]].
That’s it. You can use cron to run it every day or every week.
The method can also be used to backup other kinds of directories besides of linux home directories given the user running `rsync` has sufficient permission to the directories and files. rsync also supports copying files to remote host. Please check “man rsync” for more.