manpage updates, mostly suggested by Francois
[rsync/rsync.git] / options.c
CommitLineData
7a6421fa
AT
1/*
2 Copyright (C) Andrew Tridgell 1998
3
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.
8
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.
13
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.
17*/
18
19/* options parsing code */
20
21#include "rsync.h"
22
23
24int make_backups = 0;
25int whole_file = 0;
26int copy_links = 0;
27int preserve_links = 0;
28int preserve_hard_links = 0;
29int preserve_perms = 0;
30int preserve_devices = 0;
31int preserve_uid = 0;
32int preserve_gid = 0;
33int preserve_times = 0;
34int update_only = 0;
35int cvs_exclude = 0;
36int dry_run=0;
37int local_server=0;
38int ignore_times=0;
39int delete_mode=0;
40int one_file_system=0;
41int remote_version=0;
42int sparse_files=0;
43int do_compression=0;
44int am_root=0;
45int orig_umask=0;
46int relative_paths=0;
47int numeric_ids = 0;
48int force_delete = 0;
49int io_timeout = 0;
50int io_error = 0;
51int read_only = 0;
52int module_id = -1;
53int am_server = 0;
54int am_sender=0;
55int recurse = 0;
56int am_daemon=0;
8d9dc9f9 57int am_client=0;
a800434a 58int do_stats=0;
7a6421fa
AT
59
60int block_size=BLOCK_SIZE;
61
62char *backup_suffix = BACKUP_SUFFIX;
63char *tmpdir = NULL;
64char *config_file = RSYNCD_CONF;
65char *shell_cmd = NULL;
66
67char *rsync_path = RSYNC_NAME;
68int rsync_port = RSYNC_PORT;
69
70int verbose = 0;
71int always_checksum = 0;
72
73
74void usage(int F)
75{
76 rprintf(F,"rsync version %s Copyright Andrew Tridgell and Paul Mackerras\n\n",
77 VERSION);
b72f24c7
AT
78 rprintf(F,"Usage:\t%s [options] src user@host:dest\n",RSYNC_NAME);
79 rprintf(F,"OR\t%s [options] user@host:src dest\n",RSYNC_NAME);
80 rprintf(F,"OR\t%s [options] src dest\n",RSYNC_NAME);
81 rprintf(F,"OR\t%s [options] user@host::src dest\n",RSYNC_NAME);
82 rprintf(F,"OR\t%s [options] src user@host::dest\n",RSYNC_NAME);
83 rprintf(F,"\nOptions:\n");
7a6421fa
AT
84 rprintf(F,"-v, --verbose increase verbosity\n");
85 rprintf(F,"-c, --checksum always checksum\n");
5243c216 86 rprintf(F,"-a, --archive archive mode\n");
7a6421fa
AT
87 rprintf(F,"-r, --recursive recurse into directories\n");
88 rprintf(F,"-R, --relative use relative path names\n");
89 rprintf(F,"-b, --backup make backups (default ~ extension)\n");
90 rprintf(F,"-u, --update update only (don't overwrite newer files)\n");
91 rprintf(F,"-l, --links preserve soft links\n");
92 rprintf(F,"-L, --copy-links treat soft links like regular files\n");
93 rprintf(F,"-H, --hard-links preserve hard links\n");
94 rprintf(F,"-p, --perms preserve permissions\n");
95 rprintf(F,"-o, --owner preserve owner (root only)\n");
96 rprintf(F,"-g, --group preserve group\n");
97 rprintf(F,"-D, --devices preserve devices (root only)\n");
98 rprintf(F,"-t, --times preserve times\n");
99 rprintf(F,"-S, --sparse handle sparse files efficiently\n");
100 rprintf(F,"-n, --dry-run show what would have been transferred\n");
101 rprintf(F,"-W, --whole-file copy whole files, no incremental checks\n");
102 rprintf(F,"-x, --one-file-system don't cross filesystem boundaries\n");
103 rprintf(F,"-B, --block-size SIZE checksum blocking size\n");
104 rprintf(F,"-e, --rsh COMMAND specify rsh replacement\n");
105 rprintf(F," --rsync-path PATH specify path to rsync on the remote machine\n");
106 rprintf(F,"-C, --cvs-exclude auto ignore files in the same way CVS does\n");
107 rprintf(F," --delete delete files that don't exist on the sending side\n");
108 rprintf(F," --force force deletion of directories even if not empty\n");
109 rprintf(F," --numeric-ids don't map uid/gid values by user/group name\n");
110 rprintf(F," --timeout TIME set IO timeout in seconds\n");
111 rprintf(F,"-I, --ignore-times don't exclude files that match length and time\n");
112 rprintf(F,"-T --temp-dir DIR create temporary files in directory DIR\n");
113 rprintf(F,"-z, --compress compress file data\n");
114 rprintf(F," --exclude FILE exclude file FILE\n");
115 rprintf(F," --exclude-from FILE exclude files listed in FILE\n");
2b6b4d53
AT
116 rprintf(F," --include FILE don't exclude file FILE\n");
117 rprintf(F," --include-from FILE don't exclude files listed in FILE\n");
7a6421fa
AT
118 rprintf(F," --suffix SUFFIX override backup suffix\n");
119 rprintf(F," --version print version number\n");
120 rprintf(F," --daemon run as a rsync daemon\n");
121 rprintf(F," --config FILE specify alternate rsyncd.conf file\n");
a800434a
AT
122 rprintf(F," --port PORT specify alternate rsyncd port number\n");
123 rprintf(F," --stats give some file transfer stats\n");
7a6421fa
AT
124
125 rprintf(F,"\n");
126 rprintf(F,"the backup suffix defaults to %s\n",BACKUP_SUFFIX);
127 rprintf(F,"the block size defaults to %d\n",BLOCK_SIZE);
b72f24c7
AT
128
129 rprintf(F,"\nPlease see the rsync(1) and rsyncd.conf(5) man pages for full documentation\n");
130 rprintf(F,"See http://samba.anu.edu.au/rsync/ for updates and bug reports\n");
7a6421fa
AT
131}
132
133enum {OPT_VERSION,OPT_SUFFIX,OPT_SENDER,OPT_SERVER,OPT_EXCLUDE,
134 OPT_EXCLUDE_FROM,OPT_DELETE,OPT_NUMERIC_IDS,OPT_RSYNC_PATH,
2b6b4d53 135 OPT_FORCE,OPT_TIMEOUT,OPT_DAEMON,OPT_CONFIG,OPT_PORT,
a800434a 136 OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_STATS};
7a6421fa
AT
137
138static char *short_options = "oblLWHpguDCtcahvrRIxnSe:B:T:z";
139
140static struct option long_options[] = {
141 {"version", 0, 0, OPT_VERSION},
142 {"server", 0, 0, OPT_SERVER},
143 {"sender", 0, 0, OPT_SENDER},
144 {"delete", 0, 0, OPT_DELETE},
145 {"force", 0, 0, OPT_FORCE},
146 {"numeric-ids", 0, 0, OPT_NUMERIC_IDS},
147 {"exclude", 1, 0, OPT_EXCLUDE},
148 {"exclude-from",1, 0, OPT_EXCLUDE_FROM},
2b6b4d53
AT
149 {"include", 1, 0, OPT_INCLUDE},
150 {"include-from",1, 0, OPT_INCLUDE_FROM},
7a6421fa
AT
151 {"rsync-path", 1, 0, OPT_RSYNC_PATH},
152 {"one-file-system",0, 0, 'x'},
153 {"ignore-times",0, 0, 'I'},
154 {"help", 0, 0, 'h'},
155 {"dry-run", 0, 0, 'n'},
156 {"sparse", 0, 0, 'S'},
157 {"cvs-exclude", 0, 0, 'C'},
158 {"archive", 0, 0, 'a'},
159 {"checksum", 0, 0, 'c'},
160 {"backup", 0, 0, 'b'},
161 {"update", 0, 0, 'u'},
162 {"verbose", 0, 0, 'v'},
163 {"recursive", 0, 0, 'r'},
164 {"relative", 0, 0, 'R'},
165 {"devices", 0, 0, 'D'},
166 {"perms", 0, 0, 'p'},
167 {"links", 0, 0, 'l'},
168 {"copy-links", 0, 0, 'L'},
169 {"whole-file", 0, 0, 'W'},
170 {"hard-links", 0, 0, 'H'},
171 {"owner", 0, 0, 'o'},
172 {"group", 0, 0, 'g'},
173 {"times", 0, 0, 't'},
174 {"rsh", 1, 0, 'e'},
175 {"suffix", 1, 0, OPT_SUFFIX},
176 {"block-size", 1, 0, 'B'},
177 {"timeout", 1, 0, OPT_TIMEOUT},
178 {"temp-dir", 1, 0, 'T'},
179 {"compress", 0, 0, 'z'},
180 {"daemon", 0, 0, OPT_DAEMON},
a800434a 181 {"stats", 0, 0, OPT_STATS},
7a6421fa
AT
182 {"config", 1, 0, OPT_CONFIG},
183 {"port", 1, 0, OPT_PORT},
184 {0,0,0,0}};
185
186void parse_arguments(int argc, char *argv[])
187{
188 int opt;
189 int option_index;
190
191 while ((opt = getopt_long(argc, argv,
192 short_options, long_options, &option_index))
193 != -1) {
194 switch (opt)
195 {
196 case OPT_VERSION:
197 printf("rsync version %s protocol version %d\n",
198 VERSION,PROTOCOL_VERSION);
199 exit_cleanup(0);
200
201 case OPT_SUFFIX:
202 backup_suffix = optarg;
203 break;
204
205 case OPT_RSYNC_PATH:
206 rsync_path = optarg;
207 break;
208
209 case 'I':
210 ignore_times = 1;
211 break;
212
213 case 'x':
214 one_file_system=1;
215 break;
216
217 case OPT_DELETE:
218 delete_mode = 1;
219 break;
220
221 case OPT_FORCE:
222 force_delete = 1;
223 break;
224
225 case OPT_NUMERIC_IDS:
226 numeric_ids = 1;
227 break;
228
229 case OPT_EXCLUDE:
2b6b4d53
AT
230 add_exclude(optarg, 0);
231 break;
232
233 case OPT_INCLUDE:
234 add_exclude(optarg, 1);
7a6421fa
AT
235 break;
236
237 case OPT_EXCLUDE_FROM:
2b6b4d53
AT
238 add_exclude_file(optarg,1, 0);
239 break;
240
241 case OPT_INCLUDE_FROM:
242 add_exclude_file(optarg,1, 1);
7a6421fa
AT
243 break;
244
245 case 'h':
246 usage(FINFO);
247 exit_cleanup(0);
248
249 case 'b':
250 make_backups=1;
251 break;
252
253 case 'n':
254 dry_run=1;
255 break;
256
257 case 'S':
258 sparse_files=1;
259 break;
260
261 case 'C':
262 cvs_exclude=1;
263 break;
264
265 case 'u':
266 update_only=1;
267 break;
268
269 case 'l':
270 preserve_links=1;
271 break;
272
273 case 'L':
274 copy_links=1;
275 break;
276
277 case 'W':
278 whole_file=1;
279 break;
280
281 case 'H':
282#if SUPPORT_HARD_LINKS
283 preserve_hard_links=1;
284#else
285 rprintf(FERROR,"ERROR: hard links not supported on this platform\n");
286 exit_cleanup(1);
287#endif
288 break;
289
290 case 'p':
291 preserve_perms=1;
292 break;
293
294 case 'o':
295 preserve_uid=1;
296 break;
297
298 case 'g':
299 preserve_gid=1;
300 break;
301
302 case 'D':
303 preserve_devices=1;
304 break;
305
306 case 't':
307 preserve_times=1;
308 break;
309
310 case 'c':
311 always_checksum=1;
312 break;
313
314 case 'v':
315 verbose++;
316 break;
317
318 case 'a':
319 recurse=1;
320#if SUPPORT_LINKS
321 preserve_links=1;
322#endif
323 preserve_perms=1;
324 preserve_times=1;
325 preserve_gid=1;
326 if (am_root) {
327 preserve_devices=1;
328 preserve_uid=1;
329 }
330 break;
331
332 case OPT_SERVER:
333 am_server = 1;
334 break;
335
336 case OPT_SENDER:
337 if (!am_server) {
338 usage(FERROR);
339 exit_cleanup(1);
340 }
341 am_sender = 1;
342 break;
343
344 case 'r':
345 recurse = 1;
346 break;
347
348 case 'R':
349 relative_paths = 1;
350 break;
351
352 case 'e':
353 shell_cmd = optarg;
354 break;
355
356 case 'B':
357 block_size = atoi(optarg);
358 break;
359
360 case OPT_TIMEOUT:
361 io_timeout = atoi(optarg);
362 break;
363
364 case 'T':
365 tmpdir = optarg;
366 break;
367
368 case 'z':
369 do_compression = 1;
370 break;
371
372 case OPT_DAEMON:
373 am_daemon = 1;
374 break;
375
a800434a
AT
376 case OPT_STATS:
377 do_stats = 1;
378 break;
379
7a6421fa
AT
380 case OPT_CONFIG:
381 config_file = optarg;
382 break;
383
384 case OPT_PORT:
385 rsync_port = atoi(optarg);
386 break;
387
388 default:
389 /* rprintf(FERROR,"bad option -%c\n",opt); */
390 exit_cleanup(1);
391 }
392 }
393}
394
395
396void server_options(char **args,int *argc)
397{
398 int ac = *argc;
399 static char argstr[50];
400 static char bsize[30];
401 static char iotime[30];
402 int i, x;
403
404 args[ac++] = "--server";
405
406 if (!am_sender)
407 args[ac++] = "--sender";
408
409 x = 1;
410 argstr[0] = '-';
411 for (i=0;i<verbose;i++)
412 argstr[x++] = 'v';
413 if (make_backups)
414 argstr[x++] = 'b';
415 if (update_only)
416 argstr[x++] = 'u';
417 if (dry_run)
418 argstr[x++] = 'n';
419 if (preserve_links)
420 argstr[x++] = 'l';
421 if (copy_links)
422 argstr[x++] = 'L';
423 if (whole_file)
424 argstr[x++] = 'W';
425 if (preserve_hard_links)
426 argstr[x++] = 'H';
427 if (preserve_uid)
428 argstr[x++] = 'o';
429 if (preserve_gid)
430 argstr[x++] = 'g';
431 if (preserve_devices)
432 argstr[x++] = 'D';
433 if (preserve_times)
434 argstr[x++] = 't';
435 if (preserve_perms)
436 argstr[x++] = 'p';
437 if (recurse)
438 argstr[x++] = 'r';
439 if (always_checksum)
440 argstr[x++] = 'c';
441 if (cvs_exclude)
442 argstr[x++] = 'C';
443 if (ignore_times)
444 argstr[x++] = 'I';
445 if (relative_paths)
446 argstr[x++] = 'R';
447 if (one_file_system)
448 argstr[x++] = 'x';
449 if (sparse_files)
450 argstr[x++] = 'S';
451 if (do_compression)
452 argstr[x++] = 'z';
453 argstr[x] = 0;
454
455 if (x != 1) args[ac++] = argstr;
456
457 if (block_size != BLOCK_SIZE) {
458 sprintf(bsize,"-B%d",block_size);
459 args[ac++] = bsize;
460 }
461
462 if (io_timeout) {
463 sprintf(iotime,"--timeout=%d",io_timeout);
464 args[ac++] = iotime;
465 }
466
467 if (strcmp(backup_suffix, BACKUP_SUFFIX)) {
468 args[ac++] = "--suffix";
469 args[ac++] = backup_suffix;
470 }
471
472 if (delete_mode)
473 args[ac++] = "--delete";
474
475 if (force_delete)
476 args[ac++] = "--force";
477
478 if (numeric_ids)
479 args[ac++] = "--numeric-ids";
480
481 if (tmpdir) {
482 args[ac++] = "--temp-dir";
483 args[ac++] = tmpdir;
484 }
485
486 *argc = ac;
487}
488