2 Copyright (C) Andrew Tridgell 1998
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* options parsing code */
27 int preserve_links = 0;
28 int preserve_hard_links = 0;
29 int preserve_perms = 0;
30 int preserve_devices = 0;
33 int preserve_times = 0;
40 int one_file_system=0;
63 int block_size=BLOCK_SIZE;
65 char *backup_suffix = BACKUP_SUFFIX;
67 char *config_file = RSYNCD_CONF;
68 char *shell_cmd = NULL;
70 char *rsync_path = RSYNC_NAME;
71 int rsync_port = RSYNC_PORT;
74 int always_checksum = 0;
79 rprintf(F,"rsync version %s Copyright Andrew Tridgell and Paul Mackerras\n\n",
82 rprintf(F,"rsync is a file transfer program capable of efficient remote update\nvia a fast differencing algorithm.\n\n");
84 rprintf(F,"Usage: rsync [OPTION]... SRC [USER@]HOST:DEST\n");
85 rprintf(F," or rsync [OPTION]... [USER@]HOST:SRC DEST\n");
86 rprintf(F," or rsync [OPTION]... SRC DEST\n");
87 rprintf(F," or rsync [OPTION]... [USER@]HOST::SRC DEST\n");
88 rprintf(F," or rsync [OPTION]... SRC [USER@]HOST::DEST\n");
89 rprintf(F,"\nOptions\n");
90 rprintf(F," -v, --verbose increase verbosity\n");
91 rprintf(F," -c, --checksum always checksum\n");
92 rprintf(F," -a, --archive archive mode\n");
93 rprintf(F," -r, --recursive recurse into directories\n");
94 rprintf(F," -R, --relative use relative path names\n");
95 rprintf(F," -b, --backup make backups (default ~ extension)\n");
96 rprintf(F," -u, --update update only (don't overwrite newer files)\n");
97 rprintf(F," -l, --links preserve soft links\n");
98 rprintf(F," -L, --copy-links treat soft links like regular files\n");
99 rprintf(F," --safe-links ignore links outside the destination tree\n");
100 rprintf(F," -H, --hard-links preserve hard links\n");
101 rprintf(F," -p, --perms preserve permissions\n");
102 rprintf(F," -o, --owner preserve owner (root only)\n");
103 rprintf(F," -g, --group preserve group\n");
104 rprintf(F," -D, --devices preserve devices (root only)\n");
105 rprintf(F," -t, --times preserve times\n");
106 rprintf(F," -S, --sparse handle sparse files efficiently\n");
107 rprintf(F," -n, --dry-run show what would have been transferred\n");
108 rprintf(F," -W, --whole-file copy whole files, no incremental checks\n");
109 rprintf(F," -x, --one-file-system don't cross filesystem boundaries\n");
110 rprintf(F," -B, --block-size=SIZE checksum blocking size\n");
111 rprintf(F," -e, --rsh=COMMAND specify rsh replacement\n");
112 rprintf(F," --rsync-path=PATH specify path to rsync on the remote machine\n");
113 rprintf(F," -C, --cvs-exclude auto ignore files in the same way CVS does\n");
114 rprintf(F," --delete delete files that don't exist on the sending side\n");
115 rprintf(F," --partial keep partially transferred files\n");
116 rprintf(F," --force force deletion of directories even if not empty\n");
117 rprintf(F," --numeric-ids don't map uid/gid values by user/group name\n");
118 rprintf(F," --timeout=TIME set IO timeout in seconds\n");
119 rprintf(F," -I, --ignore-times don't exclude files that match length and time\n");
120 rprintf(F," -T --temp-dir=DIR create temporary files in directory DIR\n");
121 rprintf(F," -z, --compress compress file data\n");
122 rprintf(F," --exclude=PATTERN exclude file FILE\n");
123 rprintf(F," --exclude-from=PATTERN exclude files listed in FILE\n");
124 rprintf(F," --include=PATTERN don't exclude file FILE\n");
125 rprintf(F," --include-from=PATTERN don't exclude files listed in FILE\n");
126 rprintf(F," --suffix=SUFFIX override backup suffix\n");
127 rprintf(F," --version print version number\n");
128 rprintf(F," --daemon run as a rsync daemon\n");
129 rprintf(F," --config=FILE specify alternate rsyncd.conf file\n");
130 rprintf(F," --port=PORT specify alternate rsyncd port number\n");
131 rprintf(F," --stats give some file transfer stats\n");
132 rprintf(F," --progress show progress during transfer\n");
133 rprintf(F," -h, --help show this help screen\n");
136 rprintf(F,"the backup suffix defaults to %s\n",BACKUP_SUFFIX);
137 rprintf(F,"the block size defaults to %d\n",BLOCK_SIZE);
139 rprintf(F,"\nPlease see the rsync(1) and rsyncd.conf(5) man pages for full documentation\n");
140 rprintf(F,"See http://samba.anu.edu.au/rsync/ for updates and bug reports\n");
143 enum {OPT_VERSION,OPT_SUFFIX,OPT_SENDER,OPT_SERVER,OPT_EXCLUDE,
144 OPT_EXCLUDE_FROM,OPT_DELETE,OPT_NUMERIC_IDS,OPT_RSYNC_PATH,
145 OPT_FORCE,OPT_TIMEOUT,OPT_DAEMON,OPT_CONFIG,OPT_PORT,
146 OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_STATS, OPT_PARTIAL, OPT_PROGRESS,
149 static char *short_options = "oblLWHpguDCtcahvrRIxnSe:B:T:z";
151 static struct option long_options[] = {
152 {"version", 0, 0, OPT_VERSION},
153 {"server", 0, 0, OPT_SERVER},
154 {"sender", 0, 0, OPT_SENDER},
155 {"delete", 0, 0, OPT_DELETE},
156 {"force", 0, 0, OPT_FORCE},
157 {"numeric-ids", 0, 0, OPT_NUMERIC_IDS},
158 {"exclude", 1, 0, OPT_EXCLUDE},
159 {"exclude-from",1, 0, OPT_EXCLUDE_FROM},
160 {"include", 1, 0, OPT_INCLUDE},
161 {"include-from",1, 0, OPT_INCLUDE_FROM},
162 {"rsync-path", 1, 0, OPT_RSYNC_PATH},
163 {"one-file-system",0, 0, 'x'},
164 {"ignore-times",0, 0, 'I'},
166 {"dry-run", 0, 0, 'n'},
167 {"sparse", 0, 0, 'S'},
168 {"cvs-exclude", 0, 0, 'C'},
169 {"archive", 0, 0, 'a'},
170 {"checksum", 0, 0, 'c'},
171 {"backup", 0, 0, 'b'},
172 {"update", 0, 0, 'u'},
173 {"verbose", 0, 0, 'v'},
174 {"recursive", 0, 0, 'r'},
175 {"relative", 0, 0, 'R'},
176 {"devices", 0, 0, 'D'},
177 {"perms", 0, 0, 'p'},
178 {"links", 0, 0, 'l'},
179 {"copy-links", 0, 0, 'L'},
180 {"safe-links", 0, 0, OPT_SAFE_LINKS},
181 {"whole-file", 0, 0, 'W'},
182 {"hard-links", 0, 0, 'H'},
183 {"owner", 0, 0, 'o'},
184 {"group", 0, 0, 'g'},
185 {"times", 0, 0, 't'},
187 {"suffix", 1, 0, OPT_SUFFIX},
188 {"block-size", 1, 0, 'B'},
189 {"timeout", 1, 0, OPT_TIMEOUT},
190 {"temp-dir", 1, 0, 'T'},
191 {"compress", 0, 0, 'z'},
192 {"daemon", 0, 0, OPT_DAEMON},
193 {"stats", 0, 0, OPT_STATS},
194 {"progress", 0, 0, OPT_PROGRESS},
195 {"partial", 0, 0, OPT_PARTIAL},
196 {"config", 1, 0, OPT_CONFIG},
197 {"port", 1, 0, OPT_PORT},
200 void parse_arguments(int argc, char *argv[])
205 while ((opt = getopt_long(argc, argv,
206 short_options, long_options, &option_index))
210 rprintf(FINFO,"rsync version %s protocol version %d\n\n",
211 VERSION,PROTOCOL_VERSION);
212 rprintf(FINFO,"Written by Andrew Tridgell and Paul Mackerras\n");
216 backup_suffix = optarg;
239 case OPT_NUMERIC_IDS:
244 add_exclude(optarg, 0);
248 add_exclude(optarg, 1);
251 case OPT_EXCLUDE_FROM:
252 add_exclude_file(optarg,1, 0);
255 case OPT_INCLUDE_FROM:
256 add_exclude_file(optarg,1, 1);
300 #if SUPPORT_HARD_LINKS
301 preserve_hard_links=1;
303 rprintf(FERROR,"ERROR: hard links not supported on this platform\n");
375 block_size = atoi(optarg);
379 io_timeout = atoi(optarg);
407 config_file = optarg;
411 rsync_port = atoi(optarg);
415 /* rprintf(FERROR,"bad option -%c\n",opt); */
422 void server_options(char **args,int *argc)
425 static char argstr[50];
426 static char bsize[30];
427 static char iotime[30];
430 args[ac++] = "--server";
433 args[ac++] = "--sender";
437 for (i=0;i<verbose;i++)
451 if (preserve_hard_links)
457 if (preserve_devices)
481 if (x != 1) args[ac++] = argstr;
483 if (block_size != BLOCK_SIZE) {
484 sprintf(bsize,"-B%d",block_size);
489 sprintf(iotime,"--timeout=%d",io_timeout);
493 if (strcmp(backup_suffix, BACKUP_SUFFIX)) {
494 args[ac++] = "--suffix";
495 args[ac++] = backup_suffix;
499 args[ac++] = "--delete";
502 args[ac++] = "--partial";
505 args[ac++] = "--force";
508 args[ac++] = "--safe-links";
511 args[ac++] = "--numeric-ids";
514 args[ac++] = "--temp-dir";