Local backups with rsync (forget tar -cvf - . | (cd /dest; tar -xpf -)

Recently, I encountered the rsync man page by accident (maybe as one of the lines in the top 10 Google search results?) and was quite surprised to find rsync examples where there was no remote host in any of its arguments. Doesn't rsync stand for something like "remote synchronization"?

So here's how it works:

If you want to copy all files in a directory and all directories and files below to another directory (for example on another file system on a different disk), use the following command:

$ rsync -avz /source_dir/ /dest_dir

Note the added slash after /source_dir. This command will recursively copy all files and directories in directory /source_dir to directory /dest_dir (will create it if it doesn't exist). If you omit the trailing slash, it will create a new directory /dest_dir/source_dir. The rsync command will copy links as links, not as the original files they point to (similar to the default behavior of Solaris or GNU tar). If the rsync command was run before at least once, it will copy only the changed or newly added files. It will not remove destination files if files have been removed in the source directory.

Example: Copy all directories and files in directory /tmp/1 to empty directory /tmp/2:

  • Using the cp command (option P will copy links as links):
    $ cp -Ppr /tmp/1 /tmp/2
  • Using the tar command (Solaris or GNU. Solaris tar will report that a link has been created while GNU tar will only mention the file name of the link):
    $ mkdir /tmp/2
    $ cd /tmp/1
    $ tar -cvf - . | ( cd /tmp/2; tar -xpf -)
  • Using the rsync command:
    $ rsync -avz /tmp/1/ /tmp/2
Comments:

After I run the rsync, some error has come up, and nothing to do!
Anybody know why? Please help!
# /usr/local/bin/rsync -avz /tmp/1/ /tmp/2
ld.so.1: /usr/local/bin/rsync: fatal: libiconv.so.2: open failed: No such file or directory
Killed
#

Posted by ArChing on May 20, 2009 at 11:15 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

blogfinger

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today