jueves, 18 de agosto de 2011

Sincronizar Carpetas con rsync

Yo utilizo este sistema para mantener una copia de seguridad de un directorio de linux de 80Gb en otro equipo remoto utilizando el rsync a través de una comunicación ssh segura y sin tener que montar el recurso de red en la maquina origen.

Siendo a diario esta tarea solo tarda 3 minutos en sincronizar el directorio de backup. Esto como casi todo al gusto, se puede comprimir los datos antes de enviarlo, bien para una red lenta, pero para una red local, tener que comprimir enviar y en remoto descomprimir es mayor carga para la cpu de los 2 equipos y menos para la red por eso cada uno...

Se puede mantener un espejo borrando datos que fueron borrados en el original y copiando lo nuevo, o podemos omitir el borrar y conservar  también los datos que se eliminaron en origen pero eso conlleva mucho más espacio en disco que el espacio ocupado en origen.

rsync -e ssh -avhHK --delete /home/artemi/ root@192.168.0.2:/mnt/datos > /tmp/bck/historial.log



e: Añadir un segundo comando (el ssh)
a: (Archivo) es la opción mas importante que siempre debe estar incluida 
v: 
Lista todos los archivos que se están transfiriendo
H: Preserva los enlaces duros


Pegado parcial de la pagina man rsync
http://ss64.com/bash/rsync.html

OPTIONS SUMMARY

Here is a short summary of the options available in rsync. 
Please refer to the FULL List of OPTIONS for a complete description.

What to copy:
 -r, --recursive             recurse into directories
 -R, --relative              use relative path names
     --exclude=PATTERN       exclude files matching PATTERN
     --exclude-from=FILE     exclude patterns listed in FILE
 -I, --ignore-times          don't exclude files that match length and time
     --size-only             only use file size when determining if a file should be transferred
     --modify-window=NUM     Timestamp window (seconds) for file match (default=0)
     --include=PATTERN       don't exclude files matching PATTERN
     --include-from=FILE     don't exclude patterns listed in FILE

How to copy it:
 -n, --dry-run               show what would have been transferred
 -l, --links                 copy symlinks as symlinks
 -L, --copy-links            copy the referent of symlinks
     --copy-unsafe-links     copy links outside the source tree
     --safe-links            ignore links outside the destination tree
 -H, --hard-links            preserve hard links
 -D, --devices               preserve devices (root only)
 -g, --group                 preserve group
 -o, --owner                 preserve owner (root only)
 -p, --perms                 preserve permissions
 -t, --times                 preserve times
 -S, --sparse                handle sparse files efficiently
 -x, --one-file-system       don't cross filesystem boundaries
 -B, --block-size=SIZE       checksum blocking size (default 700)
 -e, --rsh=COMMAND           specify rsh replacement
     --rsync-path=PATH       specify path to rsync on the remote machine
     --numeric-ids           don't map uid/gid values by user/group name
     --timeout=TIME          set IO timeout in seconds
 -W, --whole-file            copy whole files, no incremental checks

Destination options:
 -a, --archive               archive mode
 -b, --backup                make backups (default ~ suffix)
     --backup-dir            make backups into this directory
     --suffix=SUFFIX         override backup suffix
 -z, --compress              compress file data
 -c, --checksum              always checksum
 -C, --cvs-exclude           auto ignore files in the same way CVS does
     --existing              only update files that already exist
     --delete                delete files that don't exist on the sending side
     --delete-excluded       also delete excluded files on the receiving side
     --delete-after          delete after transferring, not before
     --force                 force deletion of directories even if not empty
     --ignore-errors         delete even if there are IO errors
     --max-delete=NUM        don't delete more than NUM files
     --log-format=FORMAT     log file transfers using specified format
     --partial               keep partially transferred files
     --progress              show progress during transfer
 -P                          equivalent to --partial --progress
     --stats                 give some file transfer stats
 -T  --temp-dir=DIR          create temporary files in directory DIR
     --compare-dest=DIR      also compare destination files relative to DIR
 -u, --update                update only (don't overwrite newer files)

Misc Others:
     --address=ADDRESS       bind to the specified address
     --blocking-io           use blocking IO for the remote shell
     --bwlimit=KBPS          limit I/O bandwidth, KBytes per second
     --config=FILE           specify alternate rsyncd.conf file
     --daemon                run as a rsync daemon
     --no-detach             do not detach from the parent
     --password-file=FILE    get password from FILE
     --port=PORT             specify alternate rsyncd port number
 -f, --read-batch=FILE       read batch file
 -F, --write-batch           write batch file
     --version               print version number
 -v, --verbose               increase verbosity
 -q, --quiet                 decrease verbosity
 -h, --help                  show this help screen

No hay comentarios:

Publicar un comentario