Rsync

De WikiMar
Dreceres ràpides: navegació, cerca



RSync

-a Archive. Mainly propogate file permissions, ownership, timestamp, etc.
-v Verbose -vv More verbose. -vvv Even more verbose.
-e ssh: Specify the remote shell as ssh
--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 
-n Don't do any copying, but display what rsync *would* copy. For testing.
-u Update. Don't copy file if file on destination is newer.
-z Comprimeix
rsync -avz -e "ssh -p23" /media/a/_PORTABLE/prog  cube.aluzina.org:/var/www/carpeta.espai.de/htdocs/portable/_PORTABLE_UTIL/prog
rsync --delete -avz -e 'ssh -p 222' /usr/portage [email protected]:/usr/portage

Per copiar un sistema sencer:

rsync -axHv --delete-after / [email protected]:/home/test
   -x, --one-file-system       don't cross filesystem boundaries
   -H, --hard-links            preserve hard links

Per copiar un fitxer gran (ensenyar % i si es para continuar):

rsync -avr --partial --progress ...

equivalent a:

rsync -avrP ...


Script to only run rsync if $DEST responds

Més info a http://www.scrounge.org/linux/rsync.html

# Only run rsync if $DEST responds.
VAR=`ping -s 1 -c 1 $DEST > /dev/null; echo $?`
if [ $VAR -eq 0 ]; then
   rsync $OPTS $BACKDIR [email protected]$DEST:$DESTDIR
else
   echo "Cannot connect to $DEST."
fi


Force Rsync to only one folder

mkdir ~/bin/
gunzip /usr/share/doc/rsync/scripts/rrsync.gz -c > ~/bin/rrsync
chmod +x ~/bin/rrsync

.ssh/authorized_keys

command="$HOME/bin/rrsync /only/path/authorized/",no-agent-forwarding,no-port-forwarding,no-pty,no-user-rc,no-X11-forwarding ssh-rsa AAbCR623vGj976Eqz82SqECOqTP5TqAXVGUymmdyuzb4PW1TWZrb9sasQdUUBJGa4l6Pnb8UyDvPexrL2hIUudrHAIz1alWWQEKgK6ivgDZSUihzBGsRBKyrlfkeJz [email protected]


More info: https://www.whatsdoom.com/posts/2017/11/07/restricting-rsync-access-with-ssh/

More info: https://www.guyrutenberg.com/2014/01/14/restricting-ssh-access-to-rsync/


To avoid copying owner/group and permissions from a NTFS

rsync -a --no-o --no-g --no-p --delete -v --log-file=/tmp/rsync2.txt --stats --modify-window=2 --exclude ".encfs6.xml" --exclude "/\$RECYCLE.BIN" --exclude "/System Volume Information" /media/marti/W2000/ /media/W3000LUKS_ENC/

To show stats at the end

--stats

Give a nice overall percentage

--info=progress2


Using paths that contain spaces

-s, --protect-args

This option sends all filenames and most options to the remote rsync without allowing the remote shell to interpret them. This means that spaces are not split in names, and any non-wildcard special characters are not translated (such as ~, $, ;, &, etc.). Wildcards are expanded on the remote host by rsync (instead of the shell doing it). [...]

The alternative is to escape twice (using ' and \ ) the parameters.

http://askubuntu.com/questions/597605/rsync-over-ssh-path-with-spaces-does-not-work-with-quotes

See if a file is tranferred what differs

 --itemize-changes (also in the -vvv)

YXcstpoguax  path/to/file
|||||||||||
||||||||||╰- x: The extended attribute information changed
|||||||||╰-- a: The ACL information changed
||||||||╰--- u: The u slot is reserved for future use
|||||||╰---- g: Group is different
||||||╰----- o: Owner is different
|||||╰------ p: Permission are different
||||╰------- t: Modification time is different
|||╰-------- s: Size is different
||╰--------- c: Different checksum (for regular files), or
||              changed value (for symlinks, devices, and special files)
|╰---------- the file type:
|            f: for a file,
|            d: for a directory,
|            L: for a symlink,
|            D: for a device,
|            S: for a special file (e.g. named sockets and fifos)
╰----------- the type of update being done::
             <: file is being transferred to the remote host (sent)
             >: file is being transferred to the local host (received)
             c: local change/creation for the item, such as:
                - the creation of a directory
                - the changing of a symlink,
                - etc.
             h: the item is a hard link to another item (requires 
                --hard-links).
             .: the item is not being updated (though it might have
                attributes that are being modified)
             *: means that the rest of the itemized-output area contains
                a message (e.g. "deleting")


>f+++++++++ some/dir/new-file.txt
.f....og..x some/dir/existing-file-with-changed-owner-and-group.txt
.f........x some/dir/existing-file-with-changed-unnamed-attribute.txt
>f...p....x some/dir/existing-file-with-changed-permissions.txt
>f..t..g..x some/dir/existing-file-with-changed-time-and-group.txt
>f.s......x some/dir/existing-file-with-changed-size.txt
>f.st.....x some/dir/existing-file-with-changed-size-and-time-stamp.txt 
cd+++++++++ some/dir/new-directory/
.d....og... some/dir/existing-directory-with-changed-owner-and-group/
.d..t...... some/dir/existing-directory-with-different-time-stamp/

http://stackoverflow.com/questions/4493525/rsync-what-means-the-f-on-rsync-logs



Compare files by content

-c

By default rsync compares only size and mtime of the file. -c is slow but it ensures that the content is correct


To copy only the timestamps

--size-only --existing

--size-only forces rsync to compare using only the size (not also the time)

Without the --size-only, rsync will detect them as diferent files and transfer the file

To copy only the timestamps (slow)

-c --existing

-c forces rsync to compare files using checksums


Rsync to an untrusted location - encfs reverse

in case you have an encrypted zfs unit import it with the -l to ask for the passphrase

zpool import Y5000LUKSB_zfs -l

mount reverse encfs:

ENCFS6_CONFIG=/media/encfs6.xml encfs --reverse /media/TEST5000LUKSB_zfs/enc /media/enc1/
rsync -avi --stats --inplace --progress /media/enc1/ /media/TEST5000LUKSB_zfs/enc2/


For files that grow/appended --append-verify

--append-verify isn't dangerous: It will always read and compare the data on both ends and not just assume they're equal. It does this using checksums, so it's easy on the network, but it does require reading the shared amount of data on both ends of the wire before it can actually resume the transfer by appending to the target.

More info: https://unix.stackexchange.com/questions/48298/can-rsync-resume-after-being-interrupted