====== rsync ====== * [[https://linux.die.net/man/1/rsync|man page]] * http://rsync.samba.org/ Voir aussi: * https://rclone.org Si l'on veut passer des options à la commande ssh on ajoute des guillemets '"': rsync -avz -e "ssh -i ~/.ssh/une_cle_privee" remote_user@remote.com:/home/remote_folder/ /home/rsync/from_remote À noter la présence ou l'absence du slash '/' à la fin du répertoire source qui détermine si c'est le répertoire lui-même qui sera synchronisé (sans le /) ou bien son contenu (avec le /). Quelques options pour la commande rsync: -v, --verbose increase verbosity (-v -vv -vvv) -q, --quiet decrease verbosity --progress show progress during transfer -n, --dry-run show what would have been transferred -z, --compress compress file data -a, --archive archive mode. It is a quick way of saying you want recursion and want to preserve everything. -r, --recursive recurse into directories -R, --relative use relative path names -t, --times preserve times -c, --checksum always checksum -u, --update update only (don't overwrite newer files) -W, --whole-file copy whole files, no incremental checks -I, --ignore-times Normally rsync will skip any files that are already the same length and have the same time-stamp. This option turns off this behavior. --size-only only use file size when determining if a file should be transferred --existing only update files that already exist --delete delete files that don't exist on the sending side --delete-after delete after transferring, not before --force force deletion of directories even if not empty --exclude=PATTERN exclude files matching PATTERN --daemon run as a rsync daemon --password-file=FILE get password from FILE ===== Tips & tricks ===== ==== Synchro de machine ==== rsync -aP / root@5.196.33.193:/ -e="ssh -i /root/.ssh/syncdevartefacts" --exclude=/tmp/* --exclude=/proc/* --exclude=/sys/* --exclude=/dev/* --exclude=/etc/network/interfaces --exclude=/etc/resolv.conf --exclude=/root/* --exclude=/etc/mtab --exclude=/boot/* --exclude=/etc/fstab --exclude=/net/* ==== Dans un script ==== Il peut y avoir des bugs avec l’échappement (escape) des guillemets. La commande ''set -x'' au début du script peut vraiment aider puisque les commandes seront affichées dans leur version finales. Le shell sh ou bash joue aussi sur la façon dont sont échappées les guillemets. #!/bin/bash # # for debug: #set -x RMT="ssh -p 6666 -i /home/debian/.ssh/an_id_rsa_private_key" SRC="a_user@a_server:/home/a_user/wordpress" DST_PATH=/var/backups/a_user # something like : 2011-02-22_07-10 BACKUP_DATE=`date '+%F_%H-%M'` DST_BACKUP_PATH=$BACKUP_DATE LOG_FILE=$DST_PATH/$DST_BACKUP_PATH.log RSYNC_BIN=/usr/bin/rsync $RSYNC_BIN \ -e "$RMT" \ --quiet \ --archive \ --delete --delete-excluded --delete-after \ --backup --backup-dir=$DST_BACKUP_PATH \ --itemize-changes --log-file=$LOG_FILE \ --exclude='wp-content/wflogs/' \ $SRC $DST_PATH gzip $LOG_FILE ==== Parallelizing rsync ==== Quand il y a beaucoup de dossiers et fichiers on peut lancer plusieurs ''rsync'' simultanément. Le script de https://mjanja.ch/2014/07/parallelizing-rsync/ où l'on trouvera les explications détaillées. #!/usr/bin/env bash # borrowed / adapted from: https://wiki.ncsa.illinois.edu/display/~wglick/Parallel+Rsync # RSYNC SETUP RSYNC_PROG=/usr/bin/rsync # note the important use of --relative to use relative paths so we don't have to specify the exact path on dest RSYNC_OPTS="-aAXv --numeric-ids --progress --human-readable --delete --exclude=.glusterfs --relative" export RSYNC_RSH="ssh -T -c arcfour -o Compression=no -x" # ENV SETUP SRCDIR=/path/to/good/brick DESTDIR=/path/to/bad/brick # Recommend to match # of CPUs THREADS=4 BAD_NODE=server1 cd $SRCDIR # COPY # note the combination of -print0 and -0! find . -mindepth 1 -maxdepth 1 -print0 | \ xargs -0 -n1 -P$THREADS -I% \ $RSYNC_PROG $RSYNC_OPTS "%" $BAD_NODE:$DESTDIR