Hacer backups via FTP en Linux
Usaré la herramienta ftpsync que esta escrita en Perl:
Site Oficial de ftpsync: https://www.clazzes.org/projects/ftpsync/
Tarball: http://download.clazzes.org/ftpsync/
Los siguientes modulos deberan estar instalados:
File::Find;
File::Listing;
Net::FTP;
Net::Cmd;
Net::Netrc;
File::Listing;
Net::FTP;
Net::Cmd;
Net::Netrc;
En caso de faltar alguno instalarlo usando
cpan Modulo::Nombre
Mas info: http://www.cpan.org/modules/INSTALL.html
Se ejecuta el script con ./ftpsync.pl o perl ftpsync.pl de entrada va a mostrar las opciones que tenemos:
[root@vmcentos home]# /home/scripts/ftpsync.pl
FTPSync.pl 1.3.04 (2011-06-15)
ftpsync [ options ] [ localdir remoteURL ]
ftpsync [ options ] [ remoteURL localdir ]
options = [-dfgpqv] [ cfg|ftpuser|ftppasswd|ftpserver|ftpdir=value ... ]
localdir local directory, defaults to ".".
ftpURL full FTP URL, scheme
ftp://[ftpuser[:ftppasswd]@]ftpserver/ftpdir
ftpdir is relative, so double / for absolute paths as well as /
-c | -C like -i, but then prompts whether to actually do work
-d | -D turns debug output (including verbose output) on
-f | -F flat operation, no subdir recursion
-g | -G forces sync direction to GET (remote to local)
-h | -H prints out this help text
-i | -I forces info mode, only telling what would be done
-n | -N no deletion of obsolete files or directories
-l | -L follow local symbolic links as if they were directories
-p | -P forces sync direction to PUT (local to remote)
-q | -Q turns quiet operation on
-s | -S turns timestamp comparison off (only checks for changes in size)
-t | -T turns timestamp setting for local files off
-v | -V turnes verbose output on
cfg= read parameters and options from file defined by value.
ftpserver= defines the FTP server, defaults to "localhost".
ftpdir= defines the FTP directory, defaults to "." (/wo '"')
ftpuser= defines the FTP user, defaults to "ftp".
ftppasswd= defines the FTP password, defaults to "anonymous".
ignoremask= defines a regexp to ignore certain files, like .svn
timeoffset= overrules clocksync() detection with given offset in seconds
ftpsync [ options ] [ remoteURL localdir ]
options = [-dfgpqv] [ cfg|ftpuser|ftppasswd|ftpserver|ftpdir=value ... ]
localdir local directory, defaults to ".".
ftpURL full FTP URL, scheme
ftp://[ftpuser[:ftppasswd]@]ftpserver/ftpdir
ftpdir is relative, so double / for absolute paths as well as /
-c | -C like -i, but then prompts whether to actually do work
-d | -D turns debug output (including verbose output) on
-f | -F flat operation, no subdir recursion
-g | -G forces sync direction to GET (remote to local)
-h | -H prints out this help text
-i | -I forces info mode, only telling what would be done
-n | -N no deletion of obsolete files or directories
-l | -L follow local symbolic links as if they were directories
-p | -P forces sync direction to PUT (local to remote)
-q | -Q turns quiet operation on
-s | -S turns timestamp comparison off (only checks for changes in size)
-t | -T turns timestamp setting for local files off
-v | -V turnes verbose output on
cfg= read parameters and options from file defined by value.
ftpserver= defines the FTP server, defaults to "localhost".
ftpdir= defines the FTP directory, defaults to "." (/wo '"')
ftpuser= defines the FTP user, defaults to "ftp".
ftppasswd= defines the FTP password, defaults to "anonymous".
ignoremask= defines a regexp to ignore certain files, like .svn
timeoffset= overrules clocksync() detection with given offset in seconds
Para hacer backups por FTP con ejecutar este comando basta:
/home/scripts/ftpsync.pl -v -p -t /home/archivoslocales ftp://mauro:123456@10.10.22.23/backup
El -v es para que informe todo lo que haga el script (verbose mode), el -p fuerza que solo se copie de local a remoto, en caso de borrar algun fichero en remoto el lo volvera a copiar, en cambio si lo borras en local, lo borrara en remoto. Y un parametro bastante clave es el -t, si no activas este parametro te modifica las fechas y horas de todos los archivos al dia y hora que lo ha copiado al sitio remoto, la verdad es que no entiendo el porqué de dicha acción.
Luego solo basta cronearlo con Crontab.
Comentarios
Publicar un comentario