Rsync

De Wikijoan
Dreceres ràpides: navegació, cerca

Contingut

Serveix per fer còpies de seguretat remotes, amb moltes opcions. Concretament, còpies de seguretat incrementals

sudo apt-get install rsync
NAME
       rsync -- a fast, versatile, remote (and local) file-copying tool
SYNOPSIS
       Local:  rsync [OPTION...] SRC... [DEST]

       Access via remote shell:
         Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]
         Push: rsync [OPTION...] SRC... [USER@]HOST:DEST

       Access via rsync daemon:
         Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
               rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
         Push: rsync [OPTION...] SRC... [USER@]HOST::DEST
               rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST


       Usages with just one SRC arg and no DEST arg will list the source files
       instead of copying.

It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. Rsync is widely used for backups and mirroring and as an improved copy command for everyday use.

Rsync finds files that need to be transferred using a "quick check" algorithm (by default) that looks for files that have changed in size or in last-modified time. Any changes in the other preserved attributes (as requested by options) are made on the destination file directly when the quick check indicates that the file's data does not need to be updated.

Pot utilitzar SSH o RSH. No requreix privilegis de super-usuari.

Rsync copies files either to or from a remote host, or locally on the current host (it does not support copying files between two remote hosts).

There are two different ways for rsync to contact a remote system: using a remote-shell program as the transport (such as ssh or rsh) or contacting an rsync daemon directly via TCP. The remote-shell transport is used whenever the source or destination path contains a single colon (:) separator after a host specification. Contacting an rsync daemon directly happens when the source or destination path contains a double colon (::) separator after a host specification, OR when an rsync:// URL is specified (see also the "USING RSYNC-DAEMON FEATURES VIA A REMOTE-SHELL CONNECTION" section for an exception to this latter rule).

As a special case, if a single source arg is specified without a destination, the files are listed in an output format similar to "ls -l".

As expected, if neither the source or destination path specify a remote host, the copy occurs locally (see also the --list-only option).

Com a mínim l'origen o el destí han de ser remots, però no ho poden ser tots dos.

Exemple d'ús bàsic:

rsync -av /path/to/source/directory /path/to/target/directory
rsync -av /home/joan/how_to_ubuntu /media/disk/dades

-a: "archive" mode, which ensures that symbolic links, devices, attributes, permissions, ownerships, etc. are preserved in the transfer.

links: http://everythinglinux.org/rsync/

http://rsync.samba.org/ftp/rsync/rsync.html


script bash de còpies de seguretat

http://enavas.blogspot.com/2008/01/copias-de-seguridad-incrementales-con.html


per a fer la restauració:

http://www.novell.com/coolsolutions/tip/658.html


In the event that I want to perform a full data restore of the entire USERS directory, I can pull data back from the RSYNC server to the source server with a restusrs.ncf file:

rsync -rav RSYNC1::USERS --volume=DATA: users --update

This will restore any files deleted since the last backup, by reversing the source and target strings. The --update switch will ensure that any files modified since the last backup will not be overwritten.


link http://www.gnuchile.cl/index.php?not=238&id_page=59&conf=comments&blog=tsolar

En fin, aquí estoy escribiendo acerca de mis experiencias con rsync.

Para crear un servidor rsync, en su Debian (o distro similar) haga

$ apt-get install rsync

Con eso ya tendrá a su PC como servidor rsync :)

Después de eso, para respaldar desde Windows, puedes usar Deltacopy (GPLv2) Deltacopy es bastante fácil de usar, apenas se cree un perfil de respaldo en el cliente basta con un click para restaurar los archivos...

Si quieres respaldar desde un GNU/Linux puedes hacer

rsync [opciones] <directorioorigen> <directoriodestino>

Yo lo hago así:

rsync -v -rlt -z --delete /mi/directorio/a/respaldar/ /mi/directorio/de/respaldo/

y para restaurar:

rsync -v -rlt -z  /mi/directorio/de/respaldo /mi/directorio/a/respaldar/

Y creé un script y lo agregué en el crontab con el que creo un directorio según la fecha y hora en la que se realiza el respaldo. El directorio lo creo así:

FECHA=$(date +%Y_%m_%d-%H_%M_%S)
DESTDIR1="/mi/directorio/de/respaldo/$FECHA"
mkdir $DESTDIR1

el script completo es:

#!/bin/bash

BACKDIR="/mi/directorio/a/respaldar/"

FECHA=$(date +%Y_%m_%d-%H_%M_%S)
DESTDIR1="/mi/directorio/de/respaldo/$FECHA"
mkdir $DESTDIR1
DESTDIR="$DESTDIR1"

OPTS="-v -rlt -z --delete"

rsync $OPTS $BACKDIR $DESTDIR

aah me acordé que rsync trabaja con algunas carpetas configuradas pa verlas desde DeltaCopy :)

el archivo de configuración es /etc/rsyncd.conf y tiene algo así:

[respaldo]

    path = /mi/directorio/de/respaldo
    comment = Backup 
    uid = tom
    gid = tom
    read only = false
    auth users = tom
    secrets file = /etc/rsyncd.secrets

en el /etc/rsyncd.secrets están los usuarios y contraseñas así: <usuario>:<contraseña>

así que mi /etc/rsyncd.secrets es algo así:

tom:micontraseña

y para respaldar desde un GNU/Linux a otro se pone:

rsync -v -rlt -z --delete "/mi/directorio/a/respaldar" "tom@<ipdemiservidor>::respaldo/"

creo que eso es todo...

saludos :)

Update novembre 2011

rsync està explicat a classe, i la informació actualitzada:

Eines de l'usuari
Espais de noms
Variants
Accions
Navegació
IES Jaume Balmes
Màquines recreatives
CNC
Informàtica musical
joanillo.org Planet
Eines