Infos utiles sur l’utilisation de rsync et scp !
Tableau des usages
Soit A un dossier source et B un dossier destination, et chemin un dossier ou un fichier.
ID | Action | scp/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 |
Notes sur rsync
Options -r
et -a
-r
∈ -a
-a
= -rlptgoD
-a
est le mode archive, conserve les droits et les attributs.
Mieux vaut utiliser -a
dans la plupart des cas.
”/” sur la src
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
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
c
means 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
s
means the size of a regular file is different and will be updated by the file transfer.- A
t
means the modification time is different and is being updated to the sender’s value (requires--times
). An alternate value ofT
means 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
p
means the permissions are different and are being updated to the sender’s value (requires--perms
).- An
o
means the owner is different and is being updated to the sender’s value (requires--owner
and super-user privileges).- A
g
means the group is different and is being updated to the sender’s value (requires--group
and the authority to set the group).- The
u
slot is reserved for future use.- The
a
means that the ACL information changed.- The
x
means 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.