Outils pour utilisateurs

Outils du site


tech:notes_rsync

Ceci est une ancienne révision du document !


Notes rsync

Voir aussi

Voir :

CD / ISO

Source https://www.debian.org/CD/mirroring/

Veuillez utiliser au moins les options --times --links --hard-links --partial --block-size=8192. 
Cela conservera la date de dernière modification, les liens symboliques et durs et un bloc de 8192 octets
(le plus adapté pour les images de CD) sera utilisé. 
Lorsque la date de dernière modification et la taille d'un fichier n'ont pas été modifiées, 
rsync ignore le fichier, aussi --times est réellement nécessaire

Machine distante vers machine distante

rsync -ax backup:/home/wiki wiki:/home/
The source and destination cannot both be remote.
ssh -A remotehostA rsync /remote/file/on/host/a remoteHostB:/destination/

Une autre solution consiste à utiliser SSHFS Mais les UID/GID ne sont pas préservés

Pb SSHFS Transport endpoint is not connected

fusermount -uz /data

/etc/fuse.conf

user_allow_other
sshfs -o allow_other,ro -o reconnect -o ServerAliveInterval=15 root@192.168.2.12:/var/www /data -p 12345 -C

Pour debug ajouter l'option -d

sshfs -d -o allow_other,ro -o reconnect -o ServerAliveInterval=15 root@192.168.2.12:/var/www /data -p 12345 -C

Gros fichiers avec plein de zéros, iso...

Voir l'option --sparse

-S, --sparse                traite les fichiers à trous efficacement
$ ls -lsh
total 22G
 16K drwx------ 2 root root  16K août   9 10:42 lost+found
7,7G -rw-r--r-- 1 jibe jibe 120G août   9 11:18 VM152-SUPPMSM-V-clone.img
 14G -rw-r--r-- 1 jibe jibe  14G févr. 24 09:15 VM152-SUPPMSM-V-clone.qcow2

Copie dossier

Ne pas oublier le barre oblique (slash) à la fin

rsync -ax /mnt/usb_disk/ /mnt/usb_disk2/

Diff - diffing

diff -r --exclude='.git' --exclude='.gitlab' projet_plop_fork/ projet_plop_orig/

Équivalent avec rsync

rsync -rcvn --delete --exclude='.git' --exclude='.gitlab' projet_plop_fork/ projet_plop_orig/

Droits

chmod - exemple cd iso9660

chmod \ F pour File \ D pour Directory

rsync -a -H --delete --chmod=Fu+rw,Du=rwx /mnt/iso /tmp/iso

Cependant dans le cas d'un ISO CD/DVD nous préférerons :

fakeroot rsync -a -H --delete /mnt/iso /tmp/iso

chown - exemple synchro dokuwiki

rsync -axP --chown=999:999 --exclude="cache" --exclude="tmp" --exclude="attic" --delete webapp:/home/wiki/data/* /home/wiki/data/

Options SSH

rsync -o StrictHostKeyChecking=no -o CheckHostIP=no
#rsync -e "ssh -o StrictHostKeyChecking=no -o CheckHostIP=no"

Exclusion

Le chemin des fichiers à exclure est relatif au répertoire que l'on sauvegarde.

# FAUX
rsync --archive --verbose --stats --info=progress2 --delete --delete-excluded --exclude="/home/jean/tmp/" /home/jean/ /media/backup/
 
# Exclus tous les /tmp
rsync --archive --verbose --stats --info=progress2 --delete --delete-excluded --exclude="/tmp" /home/jean/ /media/backup/
 
# OK
rsync --archive --verbose --stats --info=progress2 --delete --delete-excluded -filter="- /home/jean/tmp/" /home/jean/ /media/backup/

La racine “/” est relative au dossier racine qu'on sauvegarde

Source https://fortintam.com/blog/2010/03/18/le-parametre-exclude-de-rsync/

Exclure les fichiers cachés

rsync -ax --exclude=".*" --delete /source/ /dest/

Liste bande passante / ressources

Liste bande passante / ressources --bwlimit=KBps

/usr/bin/ionice -c2 -n7 rsync -axvn --bwlimit=20480 /home/jean/ backup1:/data/bck1/home/jean/

Voir aussi

renice +19 -p $$ >/dev/null 2>&1
ionice -c3 -p $$ >/dev/null 2>&1
ntop -A
sudo /etc/init.d/ntop start

Rsync en mode daemon

Activation

/etc/default/rsync

RSYNC_ENABLE=true
systemctl enable --now rsync
systemctl status rsync
rsync rsync://pub@localhost/

Exemple de fichier de conf

/etc/rsyncd.conf

uid = swift
gid = swift
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
 
reverse lookup = false
 
 
[account]
max connections = 2
path = /srv/node
read only = false
lock file = /var/lock/account.lock
 
[container]
max connections = 4
path = /srv/node
read only = false
lock file = /var/lock/container.lock
 
[object]
max connections = 8
path = /srv/node
read only = false
lock file = /var/lock/object.lock

Autres

Installeur Debian Calamares

Running ("rsync", "-aHAXr", "--filter=-x trusted.overlay.*", "--exclude", "/proc/", "--exclude", "/sys/", "--exclude", "/dev/", "--exclude", "/run/", "--exclude", "/run/udev/", "--exclude", "/sys/firmware/efi/efivars/", "--progress", "/tmp/tmpqf5n2jx1/filesystem/", "/tmp/calamares-root-z6v29hnx")

Pb

Pb de taille

Source : https://sanitarium.net/rsyncfaq/#differentsizes

rsync -ax --delete ne fait pas forcément le sparce, et ne préserve pas les hardlinks

Pour vérifier que la copie fait bien la même taille

#echo `find . -type f -ls | awk '{print $7 "+"}'`0 | bc
echo `find /media/Disk1/ -type f -ls | awk '{print $7 "+"}'`0 | bc
echo `find /media/Disk2/ -type f -ls | awk '{print $7 "+"}'`0 | bc
rsync --delete -v -axHSc /media/Disk1/ /media/Disk2/
Option Description -c skip based on checksum, not mod-time & size -H preserve hard links -S\ --sparse handle sparse files efficiently

Pb : failed to set times on / No such file or directory

sshfs SRV_DEST:/var/www/ /home/jean/mnt/SRV_DEST
rsync -ax --bwlimit=20480 SRV_SRC01:/var/www/www.acme.fr/ /home/jean/mnt/SRV_DEST/www.acme.fr/
rsync: failed to set times on "/home/jean/mnt/SRV_DEST/www.acme.fr/htdocs/current": No such file or directory (2)

Solution : Tester avec l'option -J ou -O

rsync -ax -J --bwlimit=20480 SRV_SRC01:/var/www/www.acme.fr/ /home/jean/mnt/SRV_DEST/www.acme.fr/

Pb clef USB sync

Sur clef USB le système peut bufferiser beaucoup trop. La copie se met en pause un certain temps puis reprend. Si on interrompt le rsync le “sync” mais énormément de temps. Pendant tous ce temps il n'est pas possible de démonter la clef USB

Dans ce cas il est possible d'utiliser l'option --fsync

Note : sur du FAT il est possible d'utiliser --modify-window=1

tech/notes_rsync.1744272758.txt.gz · Dernière modification : de Jean-Baptiste

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki