informatique:rsync
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédenteProchaine révisionLes deux révisions suivantes | ||
informatique:rsync [19/07/2014 10:28] – créée cyrille | informatique:rsync [12/09/2021 09:55] – [Dans un script] Parallelizing rsync cyrille | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
====== rsync ====== | ====== rsync ====== | ||
+ | * [[https:// | ||
* http:// | * http:// | ||
- | * http://samba.anu.edu.au/rsync/ | + | |
+ | rsync -az remote_user@remote.com:/home/remote_folder/ | ||
+ | |||
+ | "'' | ||
+ | rsync -avz -e ssh remote_user@remote.com:/ | ||
+ | |||
+ | |||
+ | À noter la présence ou l' | ||
+ | |||
+ | Si l'on veut passer des options à la commande ssh on ajoute des guillemets '"': | ||
+ | |||
+ | rsync -avz -e "ssh -i ~/ | ||
+ | |||
+ | 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, | ||
+ | --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:/ | ||
+ | --exclude=/ | ||
+ | --exclude=/ | ||
+ | --exclude=/ | ||
+ | --exclude=/ | ||
+ | </ | ||
+ | |||
+ | ==== Dans un script ==== | ||
+ | |||
+ | Il peut y avoir des bugs avec l’échappement (escape) des guillemets. | ||
+ | |||
+ | La commande '' | ||
+ | |||
+ | <code bash> | ||
+ | # | ||
+ | # | ||
+ | |||
+ | # for debug: | ||
+ | #set -x | ||
+ | |||
+ | RMT=" | ||
+ | SRC=" | ||
+ | DST_PATH=/ | ||
+ | |||
+ | # something like : 2011-02-22_07-10 | ||
+ | BACKUP_DATE=`date ' | ||
+ | DST_BACKUP_PATH=$BACKUP_DATE | ||
+ | LOG_FILE=$DST_PATH/ | ||
+ | RSYNC_BIN=/ | ||
+ | |||
+ | $RSYNC_BIN \ | ||
+ | -e " | ||
+ | --quiet \ | ||
+ | --archive \ | ||
+ | --delete --delete-excluded --delete-after \ | ||
+ | --backup --backup-dir=$DST_BACKUP_PATH \ | ||
+ | --itemize-changes --log-file=$LOG_FILE \ | ||
+ | --exclude=' | ||
+ | $SRC $DST_PATH | ||
+ | |||
+ | gzip $LOG_FILE | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== Parallelizing rsync ==== | ||
+ | |||
+ | Quand il y a beaucoup de dossiers et fichiers on peut lancer plusieurs '' | ||
+ | |||
+ | Le script de https:// | ||
+ | |||
+ | <code bash> | ||
+ | # | ||
+ | # borrowed / adapted from: https:// | ||
+ | |||
+ | # RSYNC SETUP | ||
+ | RSYNC_PROG=/ | ||
+ | # note the important use of --relative to use relative paths so we don't have to specify the exact path on dest | ||
+ | RSYNC_OPTS=" | ||
+ | export RSYNC_RSH=" | ||
+ | |||
+ | # ENV SETUP | ||
+ | SRCDIR=/ | ||
+ | DESTDIR=/ | ||
+ | # 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 " | ||
+ | </code> | ||
informatique/rsync.txt · Dernière modification : 29/01/2022 14:00 de cyrille