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 delete_excluded=0;
41 int one_file_system=0;
63 int copy_unsafe_links=0;
64 int block_size=BLOCK_SIZE;
67 char *backup_suffix = BACKUP_SUFFIX;
69 char *compare_dest = NULL;
70 char *config_file = RSYNCD_CONF;
71 char *shell_cmd = NULL;
72 char *log_format = NULL;
73 char *password_file = NULL;
74 char *rsync_path = RSYNC_NAME;
75 int rsync_port = RSYNC_PORT;
79 int always_checksum = 0;
84 rprintf(F,"rsync version %s Copyright Andrew Tridgell and Paul Mackerras\n\n",
87 rprintf(F,"rsync is a file transfer program capable of efficient remote update\nvia a fast differencing algorithm.\n\n");
89 rprintf(F,"Usage: rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST\n");
90 rprintf(F," or rsync [OPTION]... [USER@]HOST:SRC DEST\n");
91 rprintf(F," or rsync [OPTION]... SRC [SRC]... DEST\n");
92 rprintf(F," or rsync [OPTION]... [USER@]HOST::SRC [DEST]\n");
93 rprintf(F," or rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST\n");
94 rprintf(F," or rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]\n");
95 rprintf(F,"SRC on single-colon remote HOST will be expanded by remote shell\n");
96 rprintf(F,"SRC on server remote HOST may contain shell wildcards or multiple\n");
97 rprintf(F," sources separated by space as long as they have same top-level\n");
98 rprintf(F,"\nOptions\n");
99 rprintf(F," -v, --verbose increase verbosity\n");
100 rprintf(F," -q, --quiet decrease verbosity\n");
101 rprintf(F," -c, --checksum always checksum\n");
102 rprintf(F," -a, --archive archive mode\n");
103 rprintf(F," -r, --recursive recurse into directories\n");
104 rprintf(F," -R, --relative use relative path names\n");
105 rprintf(F," -b, --backup make backups (default %s suffix)\n",BACKUP_SUFFIX);
106 rprintf(F," --suffix=SUFFIX override backup suffix\n");
107 rprintf(F," -u, --update update only (don't overwrite newer files)\n");
108 rprintf(F," -l, --links preserve soft links\n");
109 rprintf(F," -L, --copy-links treat soft links like regular files\n");
110 rprintf(F," --copy-unsafe-links copy links outside the source tree\n");
111 rprintf(F," --safe-links ignore links outside the destination tree\n");
112 rprintf(F," -H, --hard-links preserve hard links\n");
113 rprintf(F," -p, --perms preserve permissions\n");
114 rprintf(F," -o, --owner preserve owner (root only)\n");
115 rprintf(F," -g, --group preserve group\n");
116 rprintf(F," -D, --devices preserve devices (root only)\n");
117 rprintf(F," -t, --times preserve times\n");
118 rprintf(F," -S, --sparse handle sparse files efficiently\n");
119 rprintf(F," -n, --dry-run show what would have been transferred\n");
120 rprintf(F," -W, --whole-file copy whole files, no incremental checks\n");
121 rprintf(F," -x, --one-file-system don't cross filesystem boundaries\n");
122 rprintf(F," -B, --block-size=SIZE checksum blocking size (default %d)\n",BLOCK_SIZE);
123 rprintf(F," -e, --rsh=COMMAND specify rsh replacement\n");
124 rprintf(F," --rsync-path=PATH specify path to rsync on the remote machine\n");
125 rprintf(F," -C, --cvs-exclude auto ignore files in the same way CVS does\n");
126 rprintf(F," --delete delete files that don't exist on the sending side\n");
127 rprintf(F," --delete-excluded also delete excluded files on the receiving side\n");
128 rprintf(F," --partial keep partially transferred files\n");
129 rprintf(F," --force force deletion of directories even if not empty\n");
130 rprintf(F," --numeric-ids don't map uid/gid values by user/group name\n");
131 rprintf(F," --timeout=TIME set IO timeout in seconds\n");
132 rprintf(F," -I, --ignore-times don't exclude files that match length and time\n");
133 rprintf(F," --size-only only use file size when determining if a file should be transferred\n");
134 rprintf(F," -T --temp-dir=DIR create temporary files in directory DIR\n");
135 rprintf(F," --compare-dest=DIR also compare destination files relative to DIR\n");
136 rprintf(F," -z, --compress compress file data\n");
137 rprintf(F," --exclude=PATTERN exclude files matching PATTERN\n");
138 rprintf(F," --exclude-from=FILE exclude patterns listed in FILE\n");
139 rprintf(F," --include=PATTERN don't exclude files matching PATTERN\n");
140 rprintf(F," --include-from=FILE don't exclude patterns listed in FILE\n");
141 rprintf(F," --version print version number\n");
142 rprintf(F," --daemon run as a rsync daemon\n");
143 rprintf(F," --config=FILE specify alternate rsyncd.conf file\n");
144 rprintf(F," --port=PORT specify alternate rsyncd port number\n");
145 rprintf(F," --stats give some file transfer stats\n");
146 rprintf(F," --progress show progress during transfer\n");
147 rprintf(F," --log-format=FORMAT log file transfers using specified format\n");
148 rprintf(F," --password-file=FILE get password from FILE\n");
149 rprintf(F," -h, --help show this help screen\n");
153 rprintf(F,"\nPlease see the rsync(1) and rsyncd.conf(5) man pages for full documentation\n");
154 rprintf(F,"See http://rsync.samba.org/ for updates and bug reports\n");
157 enum {OPT_VERSION, OPT_SUFFIX, OPT_SENDER, OPT_SERVER, OPT_EXCLUDE,
158 OPT_EXCLUDE_FROM, OPT_DELETE, OPT_DELETE_EXCLUDED, OPT_NUMERIC_IDS,
159 OPT_RSYNC_PATH, OPT_FORCE, OPT_TIMEOUT, OPT_DAEMON, OPT_CONFIG, OPT_PORT,
160 OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_STATS, OPT_PARTIAL, OPT_PROGRESS,
161 OPT_COPY_UNSAFE_LINKS, OPT_SAFE_LINKS, OPT_COMPARE_DEST,
162 OPT_LOG_FORMAT, OPT_PASSWORD_FILE, OPT_SIZE_ONLY};
164 static char *short_options = "oblLWHpguDCtcahvqrRIxnSe:B:T:z";
166 static struct option long_options[] = {
167 {"version", 0, 0, OPT_VERSION},
168 {"server", 0, 0, OPT_SERVER},
169 {"sender", 0, 0, OPT_SENDER},
170 {"delete", 0, 0, OPT_DELETE},
171 {"delete-excluded", 0, 0, OPT_DELETE_EXCLUDED},
172 {"force", 0, 0, OPT_FORCE},
173 {"numeric-ids", 0, 0, OPT_NUMERIC_IDS},
174 {"exclude", 1, 0, OPT_EXCLUDE},
175 {"exclude-from",1, 0, OPT_EXCLUDE_FROM},
176 {"include", 1, 0, OPT_INCLUDE},
177 {"include-from",1, 0, OPT_INCLUDE_FROM},
178 {"rsync-path", 1, 0, OPT_RSYNC_PATH},
179 {"password-file", 1, 0, OPT_PASSWORD_FILE},
180 {"one-file-system",0, 0, 'x'},
181 {"ignore-times",0, 0, 'I'},
182 {"size-only", 0, 0, OPT_SIZE_ONLY},
184 {"dry-run", 0, 0, 'n'},
185 {"sparse", 0, 0, 'S'},
186 {"cvs-exclude", 0, 0, 'C'},
187 {"archive", 0, 0, 'a'},
188 {"checksum", 0, 0, 'c'},
189 {"backup", 0, 0, 'b'},
190 {"update", 0, 0, 'u'},
191 {"verbose", 0, 0, 'v'},
192 {"quiet", 0, 0, 'q'},
193 {"recursive", 0, 0, 'r'},
194 {"relative", 0, 0, 'R'},
195 {"devices", 0, 0, 'D'},
196 {"perms", 0, 0, 'p'},
197 {"links", 0, 0, 'l'},
198 {"copy-links", 0, 0, 'L'},
199 {"copy-unsafe-links", 0, 0, OPT_COPY_UNSAFE_LINKS},
200 {"safe-links", 0, 0, OPT_SAFE_LINKS},
201 {"whole-file", 0, 0, 'W'},
202 {"hard-links", 0, 0, 'H'},
203 {"owner", 0, 0, 'o'},
204 {"group", 0, 0, 'g'},
205 {"times", 0, 0, 't'},
207 {"suffix", 1, 0, OPT_SUFFIX},
208 {"block-size", 1, 0, 'B'},
209 {"timeout", 1, 0, OPT_TIMEOUT},
210 {"temp-dir", 1, 0, 'T'},
211 {"compare-dest", 1, 0, OPT_COMPARE_DEST},
212 {"compress", 0, 0, 'z'},
213 {"daemon", 0, 0, OPT_DAEMON},
214 {"stats", 0, 0, OPT_STATS},
215 {"progress", 0, 0, OPT_PROGRESS},
216 {"partial", 0, 0, OPT_PARTIAL},
217 {"config", 1, 0, OPT_CONFIG},
218 {"port", 1, 0, OPT_PORT},
219 {"log-format", 1, 0, OPT_LOG_FORMAT},
223 static char err_buf[100];
225 void option_error(void)
228 rprintf(FLOG,"%s", err_buf);
229 rprintf(FERROR,"%s", err_buf);
231 rprintf(FLOG,"Error parsing options - unsupported option?\n");
232 rprintf(FERROR,"Error parsing options - unsupported option?\n");
234 exit_cleanup(RERR_UNSUPPORTED);
237 /* check to see if we should refuse this option */
238 static int check_refuse_options(char *ref, int opt)
244 for (i=0; long_options[i].name; i++) {
245 if (long_options[i].val == opt) break;
248 if (!long_options[i].name) return 0;
250 name = long_options[i].name;
253 while ((p = strstr(ref,name))) {
254 if ((p==ref || p[-1]==' ') &&
255 (p[len] == ' ' || p[len] == 0)) {
256 slprintf(err_buf,sizeof(err_buf),
257 "The '%s' option is not supported by this server\n", name);
266 int parse_arguments(int argc, char *argv[], int frommain)
270 char *ref = lp_refuse_options(module_id);
272 while ((opt = getopt_long(argc, argv,
273 short_options, long_options, &option_index))
277 if (check_refuse_options(ref, opt)) return 0;
282 rprintf(FINFO,"rsync version %s protocol version %d\n\n",
283 VERSION,PROTOCOL_VERSION);
284 rprintf(FINFO,"Written by Andrew Tridgell and Paul Mackerras\n");
288 backup_suffix = optarg;
295 case OPT_PASSWORD_FILE:
296 password_file =optarg;
315 case OPT_DELETE_EXCLUDED:
324 case OPT_NUMERIC_IDS:
329 add_exclude(optarg, 0);
333 add_exclude(optarg, 1);
336 case OPT_EXCLUDE_FROM:
337 add_exclude_file(optarg,1, 0);
340 case OPT_INCLUDE_FROM:
341 add_exclude_file(optarg,1, 1);
344 case OPT_COPY_UNSAFE_LINKS:
389 #if SUPPORT_HARD_LINKS
390 preserve_hard_links=1;
392 slprintf(err_buf,sizeof(err_buf),"hard links are not supported on this server\n");
393 rprintf(FERROR,"ERROR: hard links not supported on this platform\n");
427 if (frommain) quiet++;
451 exit_cleanup(RERR_SYNTAX);
469 block_size = atoi(optarg);
473 io_timeout = atoi(optarg);
480 case OPT_COMPARE_DEST:
481 compare_dest = optarg;
505 config_file = optarg;
509 rsync_port = atoi(optarg);
517 slprintf(err_buf,sizeof(err_buf),"unrecognised option\n");
525 void server_options(char **args,int *argc)
528 static char argstr[50];
529 static char bsize[30];
530 static char iotime[30];
533 args[ac++] = "--server";
536 args[ac++] = "--sender";
540 for (i=0;i<verbose;i++)
542 /* the -q option is intentionally left out */
555 if (preserve_hard_links)
561 if (preserve_devices)
585 if (x != 1) args[ac++] = argstr;
587 if (block_size != BLOCK_SIZE) {
588 sprintf(bsize,"-B%d",block_size);
593 sprintf(iotime,"--timeout=%d",io_timeout);
597 if (strcmp(backup_suffix, BACKUP_SUFFIX)) {
598 args[ac++] = "--suffix";
599 args[ac++] = backup_suffix;
602 if (delete_mode && !delete_excluded)
603 args[ac++] = "--delete";
606 args[ac++] = "--delete-excluded";
609 args[ac++] = "--size-only";
612 args[ac++] = "--partial";
615 args[ac++] = "--force";
617 if (copy_unsafe_links)
618 args[ac++] = "--copy-unsafe-links";
621 args[ac++] = "--safe-links";
624 args[ac++] = "--numeric-ids";
627 args[ac++] = "--temp-dir";
631 if (compare_dest && am_sender) {
632 /* the server only needs this option if it is not the sender,
633 * and it may be an older version that doesn't know this
634 * option, so don't send it if client is the sender.
636 args[ac++] = "--compare-dest";
637 args[ac++] = compare_dest;