informatique:system_admin:rsync
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédente | |||
| informatique:system_admin:rsync [20/01/2025 09:26] – supprimée - modification externe (Date inconnue) 127.0.0.1 | informatique:system_admin:rsync [20/01/2025 09:26] (Version actuelle) – ↷ Page déplacée de informatique:rsync à informatique:system_admin:rsync cyrille | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | ====== rsync ====== | ||
| + | |||
| + | * [[https:// | ||
| + | * http:// | ||
| + | |||
| + | Voir aussi: | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | Si l'on veut passer des options à la commande ssh on ajoute des guillemets '"': | ||
| + | |||
| + | <code bash> | ||
| + | rsync -avz -e "ssh -i ~/ | ||
| + | </ | ||
| + | |||
| + | À noter la présence ou l' | ||
| + | |||
| + | 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> | ||
| + | #!/bin/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 " | ||
| + | </ | ||
