User Tools

Site Tools


rsync

If you want to send us your comments, please do so. Thanks
More on comments


rsync

Warnings and notes

Warning: When using --delete in some form, use --dry-run with a new command before you run the command without --dry-run otherwise a lot of files can be deleted which were not intended to be deleted
Mostly it is a good idea to run a command with --dry-run first
Warning: RTFM !
Note: rsync must be installed on both the source and the destination machine
Note: rsync sorts the files and directories prior to copying

Some options

ShortLongDescription / CommentExample
-a--archiveArchive mode; equals -rlptgoD (no -H,-A,-X). Copies files which do not exist and updates existing files
-e--rsh=COMMANDSpecify the remote shell to use--rsh=“ssh -i $HOME/.ssh/somekeyfile”
-h--human-readableOutput numbers in a human-readable format
-i--itemize-changesOutput a change-summary for all updates
-r--recursiveRecursive
-u--updateSkip files that are newer on the receiver. If the file in the destination does not exist, it is not created. Use -u in combination with -a archive option to also copy new files (and preserve more attributes?). If you do not files might not get copied
-v--verboseIncrease verbosity. -vv is also valid
-z--compressCompress during transfer
--delete-excludedSee the FILTER RULES section and --delete (which is implied) for more details

Copying behavior

Some examples of almost identical commands:

The

file3.txt

file is already in the test2 folder

rsync -iha --delete /home/user/tempdirs/test1 /home/user/tempdirs/test2

copies the folder test1 to test2 so it becomes a subfolder of test2

/home/user/tempdirs/test2/test1

Output:

cd+++++++++ test1/
>f+++++++++ test1/file1.txt
>f+++++++++ test1/file2.txt
>f+++++++++ test1/file3.txt
>f+++++++++ test1/file4.txt
>f+++++++++ test1/file5.txt

Change: A / added after test1

rsync -iha --delete /home/user/tempdirs/test1/ /home/user/tempdirs/test2

copies the files in folder test1 to folder test2 so the contents of folder test1 is equal to the contents of folder test2
Output:

.d..t...... ./
>f+++++++++ file1.txt
>f+++++++++ file2.txt
>f+++++++++ file4.txt
>f+++++++++ file5.txt

Change: A * added after test1/

rsync -iha --delete /home/user/tempdirs/test1/* /home/user/tempdirs/test2

same result only the output of the -i option differs, since the folder test1 is ommitted
Output:

>f+++++++++ file1.txt
>f+++++++++ file2.txt
>f+++++++++ file4.txt
>f+++++++++ file5.txt

The --delete option has no function in the examples above

Remove non existent files on the destination with

--delete

Nothing will be removed, non existent files are copied to the destination:

rsync -vhia --delete --stats --progress /media/interalharddisk/test/*  /media/externalharddisk/test/

Whithout the * extraneous files are removed because of the --delete option from the destination, existent files are copied to the destination:

rsync -vhia --delete --stats --progress /media/internalharddisk/test/  /media/externalharddisk/test/
rsync does not show which files are going to be deleted, nor how many.

To ignore folders in the source use the

--exclude-from

option. Multiple instances of --exclude-from are allowed
Example:

--exclude-from=/home/user/rsync.exclude.txt

Example of its contents:

.Trash-1000/
RECYCLER/
Recycled/
System Volume Information

No whitespace in front of the items, one item per line. You can find the file here.

Reading output generated by the -i, -v and -vv options. The -h option makes the output human readable and is used in conjunction with the examples. The target folder is empty
Output generated with the -i option:

Output example:
cd+++++++++ test1/
>f+++++++++ test1/file1.txt
>f+++++++++ test1/file2.txt
>f+++++++++ test1/file3.txt
>f+++++++++ test1/file4.txt
>f+++++++++ test1/file5.txt
 	

The manpage explains that: A < means that a file is being transferred to the remote host (sent)
A > means that a file is being transferred to the local host (received)
however in normal mode ( not in deamon mode) the “<” and “>” symbols
have no other meaning than telling the reader that a file is being
transferred. rsync is uni directional, just like a copy command like cp

-v

Output example:

sending incremental file list
test1/
test1/file1.txt
test1/file2.txt
test1/file3.txt
test1/file4.txt
test1/file5.txt

sent 172 bytes  received 31 bytes  406.00 bytes/sec
total size is 25.87K  speedup is 127.45 (DRY RUN)
-vv

Output example:

sending incremental file list
delta-transmission disabled for local transfer or --whole-file
test1/
test1/file1.txt
test1/file2.txt
test1/file3.txt
test1/file4.txt
test1/file5.txt
total: matches=0  hash_hits=0  false_alarms=0 data=0

sent 172 bytes  received 31 bytes  406.00 bytes/sec
total size is 25.87K  speedup is 127.45 (DRY RUN)

Copy everything preserving everything and send the structured and formatted output to a log file with the current date and time in it

rsync -ahiuv --stats --out-format="%B %i Size: %15l %20M   %f" /media/folder1/ /media/folder2 > /home/user/`date +%y%m%d.%H%M%S`.log

SSH and key file

rsync -av -e "ssh -i $HOME/.ssh/somekey" username@hostname:/from/dir/ /to/dir/

Information in the output

Do

rsync --info=help

which looks like

Use OPT or OPT1 for level 1 output, OPT2 for level 2, etc.; OPT0 silences.

BACKUP     Mention files backed up
COPY       Mention files copied locally on the receiving side
DEL        Mention deletions on the receiving side
FLIST      Mention file-list receiving/sending (levels 1-2)
MISC       Mention miscellaneous information (levels 1-2)
MOUNT      Mention mounts that were found or skipped
NAME       Mention 1) updated file/dir names, 2) unchanged names
PROGRESS   Mention 1) per-file progress or 2) total transfer progress
REMOVE     Mention files removed on the sending side
SKIP       Mention files that are skipped due to options used
STATS      Mention statistics at end of run (levels 1-3)
SYMSAFE    Mention symlinks that are unsafe

ALL        Set all --info options (e.g. all4)
NONE       Silence all --info options (same as all0)
HELP       Output this help message

Options added for each increase in verbose level:
1) COPY,DEL,FLIST,MISC,NAME,STATS,SYMSAFE
2) BACKUP,MISC2,MOUNT,NAME2,REMOVE,SKIP

Example: --info=BACKUP,MISC2,PROGRESS2,STATS3
See also the manpage about --out-format and --itemize-changes === outputoption='--out-format=“%B %i Size: %15l %20M %f”' KUP ====

BACKUP0

Output in the e-mail when ran from cron:

receiving file list ... done

To turn this off turn --info off by using --info=none and have log files created by using the --logfile option if needed
How we can have a list of files which have been backed up and no e-mail when no files are backed up? Just use --info=none :-)

STATS

Examples

STATS1

sent 335 bytes  received 3.04K bytes  2.25K bytes/sec
total size is 1.02M  speedup is 301.48

STATS2

Number of files: 107 (reg: 66, dir: 32, link: 9)
Number of created files: 0
Number of deleted files: 0
Number of regular files transferred: 0
Total file size: 1.02M bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 3.03K
File list generation time: 0.002 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 335
Total bytes received: 3.04K

sent 335 bytes  received 3.04K bytes  2.25K bytes/sec
total size is 1.02M  speedup is 301.48

STATS3

And extra: rsync[28481] (receiver) heap statistics: [88/1584]

arena:         311296   (bytes from sbrk)                                                                                                                                  
ordblks:            2   (chunks not in use)                                                                                                                                
smblks:             1                                                                                                                                                      
hblks:              2   (chunks from mmap)                                                                                                                                 
hblkhd:        532480   (bytes from mmap)                                                                                                                                  
allmem:        843776   (bytes from sbrk + mmap)                                                                                                                           
usmblks:            0                                                                                                                                                      
fsmblks:           32                                                                                                                                                      
uordblks:      205984   (bytes used)                                                                                                                                       
fordblks:      105312   (bytes free)                                                                                                                                       
keepcost:      103872   (bytes in releasable chunk)                                                                                                                        
arena:              0   (bytes from sbrk)                                                                                                                                  
ordblks:            0   (chunks not in use)                                                                                                                                
smblks:             0                                                                                                                                                      
hblks:              0   (chunks from mmap)                                                                                                                                 
hblkhd:       3956736   (bytes from mmap)                                                                                                                                  
allmem:       3956736   (bytes from sbrk + mmap)                                                                                                                           
usmblks:      3956736                                                                                                                                                      
fsmblks:       309824
uordblks:      673584   (bytes used)
fordblks:      309824   (bytes free)
keepcost:           0   (bytes in releasable chunk)

Errors

rsync connection could not mount

No such file or directory

rsync: getcwd(): No such file or directory (2)
  • Check if the directory you are in still exists. If not, move to an existent directory
    • If ran from a script check if the script does not run rsync from a non existent directory
  • Check if the directory permissions are set right

cannot stat destination

sudo rsync somefile /mnt/server/folderonserver
rsync: ERROR: cannot stat destination "/mnt/server/folderonserver": Permission denied (13)
  • If you mounted a remote directory as normal user with sshfs root can not access it. So being root or using sudo with rsync will result in the error.
  • Using a subfolder being root or using sudo with rsync will work. So this works:
sudo rsync somefile /mnt/server/folderonserver/subfolder

An unsafe link is a link which points to a file outside the scope of the copied directory tree. See --copy-unsafe-links and similar options to deal with this isseu

Can not change group

The user has not sufficient rights on the receiving side to change the group. A solution is to tar the files, change the ownership of the tar file to user and then copy

send_files failed to open

rsync: send_files failed to open "/etc/shadow": Permission denied (13)

This happens when a user runs rsync on this file which is owned by root. Solutions:

  • Run rsync as root
  • tar the file(s), change the ownership of the tar file to user, then copy

opendir

rsync: opendir "/var/log/audit" failed: Permission denied (13)

This happens when a user runs rsync on this file which is owned by root. Solutions:

  • Run rsync as root
  • tar the file(s), change the ownership of the tar file to user, then copy

Permission denied

failed to set times on

This is about directories

rsync: failed to set times on "/directory/.": Operation not permitted (1)

rsync is not able to preserve the time values of the mentioned directory
Solution: There might be a / at the end of the source directory. Remove it

mkstemp

rsync: mkstemp "/directory/.somefile.[6 letter hash]" failed: Permission denied (13)

The dot in somefile is introduced by rsync

failed to set permissions

Command

rsync -a /mnt/sourcedirectory/subdirectory/subsubdirectory/ /mnt/destinationdirectory/subdirectory/subsubdirectory

Result

rsync: failed to set permissions on "/mnt/somedirectory/subdirectory/.": Operation not permitted (1)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1207)  sender=3.1.3]

Solution

rsync -a /mnt/sourcedirectory/subdirectory/subsubdirectory /mnt/destinationdirectory/subdirectory

recv_generator: mkdir

rsync: recv_generator: mkdir "/directory/somefile" failed: Permission denied (13)

Unexpected remote arg

Cause: There is some code like

$(date +%y%m%d.%H%M%S)

in one of the options
Solution:

datenow=$(date +%y%m%d.%H%M%S)

Use $datenow in stead of $(date +%y%m%d.%H%M%S)

Unexpected remote arg: Size:

Unexpected remote arg: Size:
rsync error: syntax or usage error (code 1) at main.c(1372) [sender=3.1.3]

Cause: When using something like

outputoption='--out-format="%B %i Size: %15l %20M %f"'
rsync $outputoption source destination

in a script this error occurs
Solution: Use

  1. -out-format=“%B %i Size: %15l %20M %f”

Direct. We could not get using one of

outputoption="--out-format="%B %i Size: %15l %20M %f""
outputoption='--out-format="%B %i Size: %15l %20M %f"'

to work

"rsync: [sender] opendir"

Check the / 's in the in- or exclude file at the beginning / end of an entry
Read the manpage and rsync exclude directory not working
Make sure you do not double the path: Do no repeat the source path form the rsync command in the exclude path

rsync: chgrp failed

rsync: chgrp "/SomeDirectory/." failed: Operation not permitted (1)

Solution: There might be a / at the end of the source directory. Remove it

getcwd(): Transport endpoint is not connected (107)


Main subjects on this wiki: Linux, Debian, HTML, Microcontrollers, Privacy

RSS
Disclaimer
Privacy statement
Bugs statement
Cookies
Copyright © : 2014 - 2024 Webevaluation.nl and the authors
Changes reserved.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
rsync.txt · Last modified: 28-09-2023 10:04 by wim