You can use rsync to transfer files from either one directory to another or from one server to another. When copying over large directory structures, rsync is usually better than using cp -av. The cp command copies files and directories blindly, while rsync compares the two directories and only copies the differences. This saves time, hard drive load, system load, and if copying across a network, bandwidth. It is very useful when backing up a hard drive or an entire server. The command to use is:
# rsync -avH –delete –exclude=/junk –exclude=/otherjunk /home /backup/
rsync -avH –delete –exclude=<file/directory to exclude> <source files/directories> <destination directory>
The "a" flag will preserve important settings such as permissions, ownership, symbolic links, etc., as well as recursively copy the entire directory tree. The "v" flag is optional, and will list each file as it is copied and will give a summary of how much data was transferred. The "H" flag preserves hard links (a standard linux installation is often full of these). If you are absolutely sure that you don’t have any hard links in the data you are copying, then you can omit it, but adding it won’t hurt. The "–delete" flag means "delete anything in the destination directory that doesn’t exist in the source directory". This is useful if you are backing up a hard drive and you want to make sure that files that you removed from the main drive are removed from the backup drive as well. The "–exclude" flag allows you to skip over certain directories that you don’t want copied over to the destination directory. You can have multiple "exclude" flags.
If you want to copy your data to another server, then you can use "rsync://<hostname>/<path>" as either the source or destination. The "hostname" is the IP or full hostname of the remote server, and "path" is the exported path that is set up in the rsync configuration on the remote server.
# rsync -avH –delete –exclude=/junk –exclude=/otherjunk /home rsync://backup.server/backup_path
rsync -avH –delete –exclude=<file/directory to exclude> <source files/directories> <rsync://hostname/path>
rsync -avH –delete –exclude=<file/directory to exclude> <rsync://hostname/path> <destination directory>