FTPMIRROR
Introduction
Ftpmirror is an utility to copy directory hierarchy
(this is called ``mirror'') with FTP.
A similar perl script exists, whose name is `mirror',
but ftpmirror requires less memory than mirror.
You need perl-5.003 or later to use ftpmirror.
Please ensure that perl-5.003 or later was installed in your
environment, at first.
How to use ftpmirror
- Install ftpmirror first.
The newest version of ftpmirror is available from
ftp.intec.co.jp.
Since ftpmirror is a set of perl scripts,
you must only extract the packages.
Do one of following:
[ if you have ftpmirror-x.y.tar.gz ]
# cd /usr/local/lib
# gzip -cd < /tmp/ftpmirror-x.y.tar.gz | tar xf -
or
[ if you have ftpmirror-x.y.shar ]
# cd /usr/local/lib
# sh /tmp/ftpmirror-x.y.shar
- $prefix defined in ftpmirror must be configured as
the install directory.
The default is /usr/local/lib/ftpmirror.
# cd /usr/local/lib/ftpmirror
# vi +/prefix/ ftpmirror
...
- Create default configuration file in the "config" directory
(Please refer the "default-sample" file).
This file contains default values described in
Parameters for ftpmirror section.
# cd /usr/local/lib/ftpmirror/config
# cp default-sample default
# vi default
...
- Create package configuration files as you need.
You may define multiple packages in the default configuration file.
For more details,
please refer the package section.
The simplest way to configure a package is defining three entry,
ftp-server,
remote-directory and
local-directory.
# cp GNU-sample GNU
# vi GNU
...
- Invoke ftpmirror with the package name.
Ftpmirror reads the configuration file for the package
if there is a file, whose name is same as the package name,
in the current directory or the "config" directory,
# /usr/local/lib/ftpmirror/ftpmirror FreeBSD
- Any information about transfer is written to STDOUT.
You can define parameters for ftpmirror with
the default configuration file,
package specific configuration file,
and run-time options.
Ftpmirror overwrites parameters in order above,
e.g., run-time options are most preferred.
There are many acceptable parameters as follows:
- Parameters for system and behavior
- local-hostname: (default: `hostname`)
The hostname where ftpmirror is invoked.
- debug: (default: 0, for backward compatibility)
Set this parameter to 1 if you want see more information
in mirror session. This is only for backward compatibility.
debug=1 is equivalent to
log-priority=6.
- log-priority: (default: 5)
Loggin level. Currently, following priorities are supported.
- 0 ... EMERG : Emergency logs. Currently, nothing will be logged.
- 4 ... WARNING : Warning logs.
- 5 ... NOTICE : Logs for file transfer or file unlink.
- 6 ... INFO : Logs in compare routine, or others.
- 7 ... DEBUG : Any logs, this generates too many outputs.
- test-mode: (default: 0)
If this parameter is 1, ftpmirror prints file names to transfer
or to unlink, but no real action is performed.
- Parameters for FTP session
- ftp-server: (default: none)
The server name to connect FTP session. This must be specified
for each package.
- ftp-gateway: (default: none)
Specify this parameter if you use FTP proxy gateway such as
TIS Internet FireWall ToolKit.
You may define this with server parameter.
- ftp-user: (default: anonymous)
Login name for FTP session. If you want to use anonymous FTP,
please specify "anonymous" as this parameter.
- ftp-pass: (default: ftp-admin@`hostname`)
Password for FTP session.
- ftp-group: (default: none)
If you want change group id after logged to the server,
specify the group name.
This must be specified with ftp-gpass.
- ftp-gpass: (default: none)
If you want change group id after logged to the server,
specify a password to change group.
This must be specified with ftp-group.
- ftp-passive: (default: 0)
Set this parameter to 1 if passive connection(PASV command in FTP)
is required. This helps you if you use ftpmirror over
a SYN/ACK style firewall.
- ftp-idle: (default: 0)
If this parameter is not zero, ftpmirror tries to set idle timer
of FTP session to this value.
FTP server must support SITE IDLE command.
- ftp-max-idle: (default: 0)
If this parameter is not zero, ftpmirror tries to set idle timer
of FTP session to maximum value.
FTP server must support SITE IDLE command.
- ftp-list-method: (default: stat)
You can specify which of STAT or LIST command should be used to get
server's directory entries. Since STAT command returns server's
directory entries over control connection, it is little faster than
LIST command. Some ftp server software does not returns directory
entry which is required by ftpmirror, in that case you must
speficy as ftp-list-method = list.
- Parameters for a package
- package: (default none)
Specify the package name. This is useful if you want to have
multiple package entries in a single configuration file.
Any parameters defined after "package" are treated as a package
specific parameter.
- server: (default none)
This is used to define FTP server specific parameters.
After this parameter, any parameter are treated as the server
specific parameter,
until package or (next)server parameter will be found.
Especially, it's reasonable to specify
ftp-gateway,
ftp-passive,
remote-timezone, ...
as server parameters.
For example, here is the author's configuration:
# in default setting, most ftp-servers requires proxy.
ftp-gateway = proxy.intec.co.jp
# in local network
server = ftp.intec.co.jp
undef ftp-gateway
# use another proxy gateway, and define offset
server = ftp.triton.ad.jp
ftp-gateway = proxy2.intec.co.jp
remote-timezone = +0900
# any packages below
package = ...
- load-package
If this parameter is defined for a package,
ftpmirror tries to overload any parameters
from another package specified by this parameter.
Note that the package specified in this parameter must be
defined before this entry.
This may help you if you use
alternate-package.
- alternate-package
You can perform alternate mirroring session
when FTP login session for a package was failed.
Currently, this fail-safe session is performed
only if LOGIN session was failed.
Set this parameter to alternate package name
for alternate session.
package = FreeBSD
ftp-server = ftp.freebsd.org
remote-directory = /pub/FreeBSD
local-directory = ~/pub/FreeBSD
lslR-file = /pub/FreeBSD/ls-lR.gz
alternate-package = FreeBSD-original
package = FreeBSD-triton
load-package = FreeBSD
ftp-server = ftp.triton.ad.jp
- Parameters about mirroring
- unlink: (default: yes)
Set this parameter "yes" or 1 if you want to unlink a file
which is removed from servers directory.
You may set this parameter as "rename",
in this case, ftpmirror renames a file with a trailing Tilda('~').
- unlink-limit: (default: 0)
If this parameter is defined, ftpmirror will not remove
large files or large directories.
This may help you when server side directory hierachy is
dramatically changed.
For example, if unlink-limit is defined as 30M,
any file or directory who is larger than 30Mbytes will not
be removed. You may also specify 500K or 3G as the maximum size.
When unlink-limit is defined as 100 (e.g. no size suffix),
ftpmirror will not remote the directory who has more than
100 entries.
- compare-stat: (default: 1)
In compare routine, ftpmirror can use results of STAT/LIST or
results of SIZE/MDTM. If compare-stat is 1, ftpmirror tries to
use results of STAT/LIST to compare local/remote files.
Please set list-method parameter to
control which of STAT/LIST would be used.
- check-mtime: (default: 1)
By default, ftpmirror try to check modified times of local and
remote files. If this parameter is zero, ftpmirror does NOT
check modified time.
In this case, if local and remote files have same size ftpmirror
will only change local file timestamp to match remote one.
- list-method: (default: STAT)
By default, ftpmirror tries to send STAT command to get FTP server's
directory entries. But, in some cases, STAT does not work well.
In these case, set this parameter to "LIST".
- remote-timezone: (default: undef)
Specify the timezone of FTP server.
Since MDTM command returns GMT time stamp, this is useful only if you
run ftpmirror with compare-stat=1.
(ftpmirror tries to calculate server's timezone automatically,
if you don't specify remote-timezone).
For example, you may specify remote-timezone = +0900
if FTP server's timezone is JST.
Currently, summer time is not supported.
- lock-directory: (default: /tmp)
Ftpmirror use lock mechanism
to avoid invoking multiple ftpmirrors for a package.
lock-directory parameter means the directory to create lock file.
- temp-directory: (default: /tmp)
Ftpmirror stores temporary files to the directory specified by
this parameter. Currently, ls-lR or dirinfo files may be stored
in this directory.
- home-directory: (default: ~ftp)
You can omit some portion of the directory name
to specify local-directory
with Tilda('~') notation.
A Tilda in local-directory parameter is replaced with
the value of this parameter.
By default, the home directory of the "ftp" user is stored in
this parameter.
- remote-directory: (default: none)
You must specify the directory on the FTP server where you want to mirror
as this parameter.
Any mirror is recursively performed from this directory.
- local-directory: (default: none)
You must set this parameter to the directory in local-side host,
e.g. the directory paired with
remote-directory.
Next example shows that ftpmirror will mirror
"/pub/FreeBSD" in the FTP server
to "/ftp/pub/FreeBSD" in local.
remote-directory = /pub/FreeBSD
local-directory = /ftp/pub/FreeBSD
If home-directory is defined (or ftp user's home directory exists),
you can specify as follows:
remote-directory = /pub/FreeBSD
local-directory = ~/pub/FreeBSD
- lslR-file: (default: none)
You can use ls-lR(or similar) on the FTP server rather than
directory scan with STAT/LIST. Specify server side filename
of ls-lR(or similar) as this parameter.
If lslR-file has an extension of .gz or .Z,
gunzip or uncompress will be automatically invoked.
For example, if you mirror ftp.freebsd.org:/pub/FreeBSD with ls-lR.gz,
you may specify as next:
ftp-server = ftp.freebsd.org
remote-directory = /pub/FreeBSD
local-directory = ~/pub/FreeBSD
lslR-file = /pub/FreeBSD/ls-lR.gz
- lslR-map: (default: none)
When you use lslR-file,
an output of ls -lR (that is, contents of lslR-file)
may have invalid top directory.
This is because, the directory where ls -lR was invoked is site-dependent.
You can specify substitute rules of the path name with lslR-map.
For example,
ftp.iij.ad.jp:/pub/GNU/ls-lR.Z has path names such as
GNU/gcc-2.7.2.tar.gz, but prepended GNU should
be dot('.') to mirror the directory hierarchy.
In this case, you should define lslR-map as:
lslR-file = /pub/GNU/ls-lR.Z
lslR-map = /^GNU/./
- transfer-file-regexp: (default: matches all)
Regular expressions(perl's regular expression) to match filenames
to transfer.
Ftpmirror tries to transfer only files on the server
which matches to this expression.
Any filename on the FTP server is represented as relative path
(from remote-directory) beginning with "./".
That is, if remote-directory is configured as "/pub/FreeBSD",
the file "/pub/FreeBSD/2.1.5-RELEASE/README.TXT" on the server
is represented as "./2.1.5-RELEASE/README.TXT".
Some examples follow:
transfer-file-regexp += !/~$/
transfer-file-regexp += !/\/\.in/
transfer-file-regexp += !/\/\.nfs/
With this configuration, ftpmirror does NOT transfer files
end with "~" and begin with ".in" or ".nfs".
(Notes: "=" means replacing a parameter value,
and "+=" means appending a parameter string)
transfer-file-regexp += /\/bash-/
transfer-file-regexp += /\/gcc-/
transfer-file-regexp += !
With adobe configuration, ftpmirror tries to transfer bash-* and
gcc-* files, but not others.
The last line in this example means
ftpmirror does NOT transfer by default.
- transfer-directory-regexp: (default: matches all)
Regular expressions(perl's regular expression) to match directory
names to scan in a FTP server.
Note that any directory in a FTP server is represented with trailing
slash ('/').
For example, next shows configuration to avoid ftpmirror
NOT to scan(off course, this means NOT to transfer) directories
whose names are "lost+found", or directories ended with '~'.
transfer-directory-regexp += !/\/lost+found\/$/
transfer-directory-regexp += !/~\/$/
- override-file-regexp: (default: matches all)
Regular expressions(perl's regular expression) to match files
you can override in local directories.
In actual mirror session,
ftpmirror tries to transfer files which match
transfer-file-regexp,
and also match override-file-regexp.
Any file which does not match override-file-regexp
will not be modified by ftpmirror.
In the next example, ftpmirror tries to transfer bash-* files,
but not modified any other files. This is useful when you want
to get files from multiple FTP servers
to a single local-side directory.
transfer-file-regexp += /\/bash-/
transfer-file-regexp += !
override-file-regexp += /\/bash-/
override-file-regexp += !
- override-directory-regexp: (default: matches all)
Regular expressions(perl's regular expression) to match directories
ftpmirror will modify.
You can transfer directories from multiple FTP
servers to a single local-side directory with this parameter.
Following example shows that you can transfer the FreeBSD-nonUS
into the FreeBSD directory.
package = FreeBSD
ftp-server = ftp.tokyonet.ad.jp
remote-directory = /pub/FreeBSD
local-directory = ~/pub/FreeBSD
override-directory-regexp += !/\.\/FreeBSD-nonUS\//
package = FreeBSD-nonUS
ftp-server = ftp.waseda.ac.jp
remote-directory = /pub/FreeBSD-nonUS
local-directory = ~/pub/FreeBSD/FreeBSD-nonUS
- md5-program: (default: path name for md5 program if exists)
Used to calculate MD5 checksum when you use
directory information described below.
- load-local-dirinfo: (default: 0)
Set this parameter to 1 if you want to load local ".dirinfo" files.
A ".dirinfo" file contains
directory information described below.
- store-local-dirinfo: (default: 0)
Set this parameter to 1 if you want to generate ".dirinfo" files
in local-side directories after each mirror session.
A ".dirinfo" file contains
directory information described below.
- load-remote-dirinfo: (default: 0)
Set this parameter to 1 if you want to load and use directory
information stored in the FTP server.
Using directory information,
you can mirror files without STAT/LIST/SIZE/MDTM,
and ftpmirror can check MD5 checksum of files.
- override-file-uid: (default: 0)
You can specify owner of files/directories in local. Any files
and directories which match override-*-regexp,
will be owned by this user id.
If ftpmirror is invoked by non privileged user,
this parameter is ignored.
- override-file-gid: (default: 0)
Same as override-file-uid,
but this parameter is for group id.
Note that if one of override-file-uid
and override-file-gid is defined,
any file which matches override-*-regexp (even if it is
not transfered) will be modified with chown.
- override-file-mode: (default: root -> 0444, other -> 0644)
You can specify local-side file mode.
Ftpmirror applies chmod to any file which matches
override-*-regexp if this parameter is specified.
- override-directory-mode: (default: 0755)
Same as override-file-mode,
but this parameter is for directories.
- default-file-uid: (default: 0)
Undef override-file-uid,
and set this parameter to specify default owner of local-side files.
Ftpmirror decides file owner in order:
override-file-uid, owner in FTP server,
default-file-uid.
- default-file-gid: (default: 0)
Same as default-file-uid, but this parameter is for group id.
- default-file-mode: (default: root -> 0444, other -> 0644)
Undef override-file-mode
and you can specify default file mode.
Ftpmirror tries to change file mode
in order: override-file-mode,
file mode in FTP server, default-file-mode.
Note that since file mode is masked with 0777, you can not set
setuid/setgid file modes.
- default-directory-mode: (default: 0755)
Same as default-file-mode,
but this parameter is for a directory mode.
You can specify parameters by command line options.
For example, if you want to invoke ftpmirror with test mode
(no actual transfer), you can type:
# ftpmirror --test-mode=1 FreeBSD
As in this example, any parameter must be prepended by "--"
in command line options.
Parameters are configured as follows:
- Parameters defined in command line option are most preferred.
- If not defined in command line option, parameters in package
specific configuration file is used.
- If defined in neither command line option nor package
specific configuration file, ftpmirror activates parameters in
the default configuration file.
- Otherwise, ftpmirror's default value
(defined in param.pl) is used.
Ftpmirror-1.2 or later can generate or use directory information.
Directory information is stored in ".dirinfo" file in each directory,
and used by ftpmirror in directory compare stage.
Using directory information, you can mirror directory hierarchy more
efficiently, and more completely.
For example, directory information contains following entries:
file = LICENSE
md5checksum = 83cdabcad3c9c3480faa6a75c47c7207
modified = 800142639
size = 4631
owner = root
group = wheel
directory = OLD
begin-update = 842336105
end-update = 842336105
owner = root
group = wheel
symlink = Welcome.html
linkto = ../index.html
owner = root
group = wheel
directory = archive
begin-update = 842336105
end-update = 842336105
owner = root
group = wheel
file = index
md5checksum = b5aeac559ee486a0f12493ce52f216f9
modified = 801170780
size = 799
owner = root
group = wheel
....
In directory information,
any file must be defined in a file-type entry.
Currently, there are three file-types:
- file = file-name ... a normal file
- symlink = link-file ... a symbolic link
- directory = dir-name ... a directory
and, each file-type is followed by some parameters:
- file file-type
- size
- modified (last modified time)
- md5checksum
- owner
- group
- symlink file-type
- directory file-type
- begin-update (start time of last update)
- end-update (end time of last update)
- owner
- group
Ftpmirror tries to compare files in local
and remote with these entries.
For example, ftpmirror compares as:
- file file-type
Are sizes same? and are md5checksums same?
- symlink file-type
Do they point same file?
- directory file-type
Is the begin-time of last update of local directory is before
the end-time of last update of remote directory?
Especially, comparing directory update times are effective,
if no file is changed in the remote directory, because ftpmirror
do nothing about the directory (even directory scan is skipped).
Ftpmirror generate ".dirinfo" file
if store-local-dirinfo parameter
is 1. You can also generate this file with mkdirinfo:
# mkdirinfo /ftp/pub/utils
mirror.sh - auto mirroring script
Ftpmirror package contains shell script mirror.sh.
This is a script to mirror automatically(e.g., by using cron).
The author mirrors by this script, daily, weekly and monthly.
Here is a simple way to use mirror.sh
- Create list.xxx in the directory defined as $prefix.
This file contains a list of package names you want to mirror.
An empty line or a line begins with # is ignored.
- Invoke mirror.sh. If you create $prefix/list.daily in
adobe stage, please type:
# /usr/local/lib/ftpmirror/mirror.sh daily
and, you can mirror all packages in the list file.
- By default, any output is logged to /var/log/mirror.xxx
if you use mirror.sh. Mirror.sh rotate these log files with
rotate. So you should install this package,
or comment out some potion calling rotate from mirror.sh.
Notice
Ftpmirror uses STAT or LIST, and SIZE/MDTM commands
to compare files in local and remote directory.
Since LIST command requires new TCP
connection per command, it may take many time if network is so slow.
Using ls-lR files (or directory information, if server supports it)
may be efficient, if you must mirror on a slow network.
If clocks of FTP server and local machine are different too much,
ftpmirror may fail to transfer files.
Please keep your clock of your machine correctly.
NTP is a good way to keep your clock right.
Mailing list for ftpmirror
Technical questions, suggestions, bug reports are welcome.
If you are interesting to ftpmirror, there is a mailing-list
to discuss about ftpmirror.
To subscribe, send a message
subscribe ftpmirror
to
majordomo@ftp.intec.co.jp.
Credits
I would like to thank to anyone who helped me by testing,
bug-reports, suggestions, sending patches.
Especially, members in
RingProject helped me by
heavy testing :-) and many suggestions.
Miscellaneous...
Please read COPYRIGHT for copyright notice.
Any comments, bug fixes, suggestions are welcome.
Please contact to
Ikuo Nakagawa
<ikuo@intec.co.jp>.
Last updated: 1997/01/27 by Ikuo Nakagawa