Outils pour utilisateurs

Outils du site


tech:notes_rsync

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
tech:notes_rsync [2025/06/25 15:13] Jean-Baptistetech:notes_rsync [2026/07/16 12:07] (Version actuelle) Jean-Baptiste
Ligne 1: Ligne 1:
 +<!DOCTYPE markdown>
 +{{tag>Brouillon rsync SSH}}
 +
 +# Notes rsync
 +
 +Voir aussi
 +* SyncThing
 +* https://github.com/tillberg/gut
 +* `gzip --rsyncable`
 +
 +Voir :
 +* [[reseau_linux_pile_tcp_ip_rto_min_scripts|Mesures - rsync]]
 +
 +### 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
 +
 +~~~bash
 +rsync -ax backup:/home/wiki wiki:/home/
 +~~~
 +
 +~~~
 +The source and destination cannot both be remote.
 +~~~
 +
 +~~~bash
 +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
 +
 +~~~bash
 +fusermount -uz /data
 +~~~
 +
 +`/etc/fuse.conf`
 +~~~
 +user_allow_other
 +~~~
 +
 +~~~bash
 +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`
 +~~~bash
 +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
 +~~~bash
 +rsync -ax /mnt/usb_disk/ /mnt/usb_disk2/
 +~~~
 +
 +
 +### Utilisation de l'option --files-from
 +
 +~~~bash
 +rsync -anv --files-from=push.lst / /tmp/plop/
 +~~~
 +
 +
 +### rsync avec find
 +
 +~~~bash
 +# rsync --files-from=<(find ~/DATA/ -type f -name '*.txt' -printf "%P\n") ~/DATA/ ~/DATA2/
 +# find ~/DATA/ -name '*.txt' -printf %P\\0 | rsync --files-from=- --from0 ~/DATA/ ~/DATA2/
 +
 +cd ~/DATA/
 +find . -type f -name '*.txt' -exec rsync -av -R {} ~/DATA2/ \;
 +~~~
 +
 +
 +
 +
 +### Diff - diffing 
 +
 +~~~bash
 +diff -r --exclude='.git' --exclude='.gitlab' projet_plop_fork/ projet_plop_orig/
 +~~~
 +
 +Équivalent avec rsync
 +~~~bash
 +rsync -rcvn --itemize-changes --delete --exclude='.git' --exclude='.gitlab' projet_plop_fork/ projet_plop_orig/ | sed -s 's%^[^ ]\+ %%'
 +~~~
 +
 +
 +
 +
 +### Droits
 +
 +chmod - exemple cd iso9660
 +
 +chmod \\
 +**F** pour File \\
 +**D** pour Directory
 +
 +~~~bash
 +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 :
 +~~~bash
 +fakeroot rsync -a -H --delete /mnt/iso /tmp/iso
 +~~~ 
 +
 +chown - exemple synchro dokuwiki 
 +~~~bash
 +rsync -axP --chown=999:999 --exclude="cache" --exclude="tmp" --exclude="attic" --delete webapp:/home/wiki/data/* /home/wiki/data/
 +~~~
 +
 +### Options SSH
 +
 +~~~bash
 +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. ** 
 +
 +~~~bash
 +# 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
 +~~~bash
 +rsync -ax --exclude=".*" --delete /source/ /dest/
 +~~~
 +
 +### Liste bande passante / ressources 
 +
 +Liste bande passante / ressources
 +`--bwlimit=KBps`
 +~~~bash
 +/usr/bin/ionice -c2 -n7 rsync -axvn --bwlimit=20480 /home/jean/ backup1:/data/bck1/home/jean/
 +
 +# systemd-run -p IOWeight=10 rsync -axvn --bwlimit=20480 /home/jean/ backup1:/data/bck1/home/jean/
 +~~~
 +
 +Voir aussi
 +
 +~~~bash
 +renice +19 -p $$ >/dev/null 2>&1
 +ionice -c3 -p $$ >/dev/null 2>&1
 +~~~
 +
 +~~~bash
 +ntop -A
 +sudo /etc/init.d/ntop start
 +~~~
 +
 +
 +## Rsync en mode daemon
 +
 +
 +Voir :
 +* https://doc.ubuntu-fr.org/tutoriel/serveur_de_synchronisation_avec_rsync
 +* https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/managing_confined_services/sect-managing_confined_services-rsync-configuration_examples7
 +* https://docs.openstack.org/newton/config-reference/object-storage/rsyncd.html
 +
 +Man Fr (old)
 +* http://www.delafond.org/traducmanfr/man/man5/rsyncd.conf.5.html
 +
 +Man recent
 +* https://download.samba.org/pub/rsync/rsyncd.conf.5
 +
 +
 +### Activation
 +
 +`/etc/default/rsync`
 +~~~bash
 +RSYNC_ENABLE=true
 +~~~
 +
 +~~~bash
 +systemctl enable --now rsync
 +systemctl status rsync
 +~~~
 +
 +~~~bash
 +rsync rsync://pub@localhost/
 +~~~
 +
 +
 +Exemple de fichier de conf
 +* https://github.com/openstack/swift/blob/master/etc/rsyncd.conf-sample
 +* https://docs.openstack.org/swift/latest/development_saio.html
 +
 +`/etc/rsyncd.conf`
 +~~~ini
 +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
 +~~~bash
 +#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
 +~~~
 +
 +~~~bash
 +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
 +
 +~~~bash
 +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`
 +~~~bash
 +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`
 +
  

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki