May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories

May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

rsync

rsync examples from command line.

 

To copy all the files in /home/lokams/* of remote host to local directory /backup/home/lokams/
# rsync -e ssh -avz –delete –exclude dir/* –delete-excluded –stats user@remotehost:/home/lokams/ /backup/home/lokams/

To copy the directory /home/lokams of remote host to local directory /backup/home. Directory “lokams” will get created in /backup/home.
# rsync -e ssh -avz –delete –exclude-from=~/.rsync/excludeFile –delete-excluded –stats user@remotehost:/home/lokams /backup/home/

To ignore the permissions errors while copying to remote windows/mac systems, use “-rlt” option.
# rsync -e ssh -avz –delete –exclude dir/* –delete-excluded –stats -rlt user@remotehost:/home/lokams/ /backup/home/lokams/

rsync behaves differently if the source directory has a trailing slash. Study and learn the difference between the following two commands before moving on. Use the -n option to rsync when testing to preview what would happen.

$ rsync -n -av /tmp .
$ rsync -n -av /tmp/ .

More rsync examples:
————————–

# rsync -crogpvltz -e ssh –exclude “bin” –exclude “ifany” –delete –delete-after –bwlimit 20 root@10.144.17.1:/apps/uae/ /apps/uae > /apps/uae/logs/sync.log

# rsync -avz -e ssh root@remotehost:/backup/reptest /backtmp/reptest/

# rsync -avz -e ssh /logstage/archive/DXBSEC/NODE0000/ db2inst1@10.20.202.236:/db2/archivelog/security/logstage/retrieve/DXBSEC/NODE0000/

# rsync -e ssh -avz –timeout=999 –delete –exclude dir-or-file-to-exclude –delete-excluded –stats -rlt user@remotehost:/home/lokams/

rsync useful options:
————————-

-a, –archive archive mode, equivalent to -rlptgoD
-n, –dry-run show what would have been transferred ( Preview mode )

-c – always checksum
-r – recursive into directories
-o – preserve owner
-g – preserve group
-p – preserve permissions
-t – preserve times
-v – verbose
-l – copy symlinks as symlinks
-z – compress file data
-P – show progress during transfer
-q – quite (decrease verbosity)
-e – specify the remote shell
-b – make backup
-R – Use relative path names
-u – skip files that are newer on the receiver

–stats give some file-transfer stats
–timeout=TIME set I/O timeout in seconds

–backup-dir – make backups into this directory
–bwlimit=KBPS – limit I/O bandwidth, KBytes per second
–delete – delete files that don’t exist on the sending side
–delete-after – receiver deletes after transferring, not before
–daemon run as an rsync daemon
–address=ADDRESS bind to the specified address
–exclude=PATTERN exclude files matching PATTERN
–exclude-from=FILE exclude patterns listed in FILE
–include=PATTERN don’t exclude files matching PATTERN
–include-from=FILE don’t exclude patterns listed in FILE
–min-size=SIZE don’t transfer any file smaller than SIZE
–max-size=SIZE don’t transfer any file larger than SIZE

# –numeric-ids:
Tells rsync to not map user and group id numbers local user and group names
# –delete:
Makes server copy an exact copy of the source by removing any files that have been removed on the remote machine

1 comment to rsync

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>