Développeur FullStack & Devops

Notes et mémos techniques


La commande rsync permet de synchroniser 2 dossiers en passant par une connexion ssh (par défaut, peut etre modifié avec l'argument -e). Il est de ce fait possible de configurer les options du client via le fichier .ssh/config.

La puissance de rsync vient de sa stabilité/longévité et du nombre de ses options.

Backup photos MAC

time rsync ./2000/ /Volume/......./2000/ -vrth --delete


La commande suivante copie du dossier local /dossier-source vers le serveur backup-server (port 1111 avec l'option -p) dans le dossier /dossier-de-backup-du-serveur/ en utilisant les credentials du user ssh ssh-backup-user. L'option --delete permet de supprimer à destination les fichiers supprimés à la source.

rsync -avzCh --delete -p 1111 /dossier-source/ ssh-backup-user@backup-server:/dossier-de-backup-du-serveur/

Options courrantes de rsync

--rsh=COMMAND, -e
              This option allows you to choose an alternative remote shell program to use for communication between the local and remote  copies  of  rsync. Typically, rsync is configured to use ssh by default, but you may prefer to use rsh on a local network.

--archive, -a
              This is equivalent to `-rlptgoD`.
			  It is a quick way of saying you want recursion and want to preserve almost everything.  
			  Be aware that it does not include preserving ACLs (-A), xattrs (-X), atimes (-U), crtimes (-N), nor the finding and preserving of hardlinks (-H).
 --dry-run, -n
              This  makes  rsync perform a trial run that doesn't make any changes (and produces mostly the same output as a real run).  It is most commonly used in combination with the --verbose, -v and/or --itemize-changes, -i options to see what an rsync command is going to do before one actually runs it.

              This  tells rsync to delete extraneous files from the receiving side (ones that aren't on the sending side), but only for the directories that are being synchronized.
 --compress, -z
              With this option, rsync compresses the file data as it is sent to the destination machine, which reduces the amount of data being transmitted

   --cvs-exclude, -C
		  This is a useful shorthand for excluding a broad range of files that you often don't want to transfer between systems. 

              This option forces all files to be owned by USER with group GROUP. 
rédigé le 08/03/22 par Behrouze
A proposCheat SheetsOutilsVidéos