Infos utiles sur l’utilisation de rsync et scp.
Tableau des usages
| ID | Action | scp ou cp | rsync (A≠A/ mais B=B/) |
|---|---|---|---|
| 1 | Dépose dans dossier destination | scp -r A B si ∄B/A sinon 3 |
rsync -a A B |
| 2 | Fusionne - si conflit chemin : remplace par source - si chemin non présent dans source : suppression dans destination |
❌ | rsync -a --del A/ B |
| 3 | Fusionne - si conflit chemin : remplace par source |
scp -r A B si ∃B/A sinon 1 |
rsync -a A/ B si ∃B sinon 6 |
| 4 | Fusionne - si conflit chemin : conserve la destination |
❌ | rsync -a --ignore-existing A/ B |
| 5 | Fusionne - si conflit chemin : remplace par plus récent - si chemin non présent dans source : conservation dans destination |
❌ | rsync -a -u A/ B |
| 6 | Copie en renommant | scp -r A B si ∄B sinon 3 ou 1 |
rsync -a A/ B si ∄B sinon 3 |
| 7 | Fusionne - si conflit chemin : remplace par plus récent - si chemin non présent dans source : suppression dans destination |
❌ | rsync -a --del -u A/ B |
Symboles :
- A un dossier source
- B un dossier destination
- B/A le chemin désignant B contenant A
- ∃ : il existe (∃B/A : il existe le chemin B/A)
- ∄ : il n’existe pas (∄B/A : il n’existe pas le chemin B/A )
- le terme “chemin” désigne n’importe quel chemin qui pointe vers un dossier ou un fichier
rsync : Utilisation du / sur la source
Le / sur la source (ex : src/) peut être interprété comme Fusionne avec le dossier de destination ou crée le si besoin.
Sans le /, on peut l’interpréter comme Dépose dans le dossier de destination.
Commandes équivalentes :
rsync -a /src/foo /dest
rsync -a /src/foo/ /dest/foo
Notes sur rsync
Options -a et -r
-aest le mode archive, conserve les droits et les attributs. C’est le mode le plus utilisé.-a=-rlptgoD-r∈-a:-rpour récursive lorsque qu’on souhaite copier un dossier. Donc-acopie aussi l’intégralité d’un dossier.
Dryrun
Pour vérifier ce que va faire rsync avant de lancer une vraie commande, on peut utiliser -n (ou --dry-run) pour tester la commande sans aucun changement, et -i (ou --itemize-changes) pour afficher en sortie un résumé de toutes les mises à jour.
La documentation rsync dit les choses suivantes sur -i :
The attribute that is associated with each letter is as follows:
- A
cmeans either that a regular file has a different checksum (requires--checksum) or that a symlink, device, or special file has a changed value. Note that if you are sending files to an rsync prior to 3.0.1, this change flag will be present only for checksum-differing regular files.- A
smeans the size of a regular file is different and will be updated by the file transfer.- A
tmeans the modification time is different and is being updated to the sender’s value (requires--times). An alternate value ofTmeans that the modification time will be set to the transfer time, which happens when a file/symlink/device is updated without –times and when a symlink is changed and the receiver can’t set its time. (Note: when using an rsync 3.0.0 client, you might see the s flag combined with t instead of the proper T flag for this time-setting failure.)- A
pmeans the permissions are different and are being updated to the sender’s value (requires--perms).- An
omeans the owner is different and is being updated to the sender’s value (requires--ownerand super-user privileges).- A
gmeans the group is different and is being updated to the sender’s value (requires--groupand the authority to set the group).- The
uslot is reserved for future use.- The
ameans that the ACL information changed.- The
xmeans that the extended attribute information changed.
Barre de progression
- Pour chacun des fichiers :
-vh --progress - Pour une barre de transfert globale :
--info=progress2 -h - Pour avoir des statistiques à la fin du transfert
--stats
Note sur scp
Il semblerait que scp soit en phase d’obsolescence ! Il est donc préférable d’utiliser rsync de manière générale.