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;
60 int block_size=BLOCK_SIZE;
62 char *backup_suffix = BACKUP_SUFFIX;
64 char *config_file = RSYNCD_CONF;
65 char *shell_cmd = NULL;
67 char *rsync_path = RSYNC_NAME;
68 int rsync_port = RSYNC_PORT;
71 int always_checksum = 0;
76 rprintf(F,"rsync version %s Copyright Andrew Tridgell and Paul Mackerras\n\n",
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");
84 rprintf(F,"-v, --verbose increase verbosity\n");
85 rprintf(F,"-c, --checksum always checksum\n");
86 rprintf(F,"-a, --archive archive mode\n");
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");
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");
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");
122 rprintf(F," --port PORT specify alternate rsyncd port number\n");
123 rprintf(F," --stats give some file transfer stats\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);
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");
133 enum {OPT_VERSION,OPT_SUFFIX,OPT_SENDER,OPT_SERVER,OPT_EXCLUDE,
134 OPT_EXCLUDE_FROM,OPT_DELETE,OPT_NUMERIC_IDS,OPT_RSYNC_PATH,
135 OPT_FORCE,OPT_TIMEOUT,OPT_DAEMON,OPT_CONFIG,OPT_PORT,
136 OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_STATS};
138 static char *short_options = "oblLWHpguDCtcahvrRIxnSe:B:T:z";
140 static 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},
149 {"include", 1, 0, OPT_INCLUDE},
150 {"include-from",1, 0, OPT_INCLUDE_FROM},
151 {"rsync-path", 1, 0, OPT_RSYNC_PATH},
152 {"one-file-system",0, 0, 'x'},
153 {"ignore-times",0, 0, 'I'},
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'},
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},
181 {"stats", 0, 0, OPT_STATS},
182 {"config", 1, 0, OPT_CONFIG},
183 {"port", 1, 0, OPT_PORT},
186 void parse_arguments(int argc, char *argv[])
191 while ((opt = getopt_long(argc, argv,
192 short_options, long_options, &option_index))
197 printf("rsync version %s protocol version %d\n",
198 VERSION,PROTOCOL_VERSION);
202 backup_suffix = optarg;
225 case OPT_NUMERIC_IDS:
230 add_exclude(optarg, 0);
234 add_exclude(optarg, 1);
237 case OPT_EXCLUDE_FROM:
238 add_exclude_file(optarg,1, 0);
241 case OPT_INCLUDE_FROM:
242 add_exclude_file(optarg,1, 1);
282 #if SUPPORT_HARD_LINKS
283 preserve_hard_links=1;
285 rprintf(FERROR,"ERROR: hard links not supported on this platform\n");
357 block_size = atoi(optarg);
361 io_timeout = atoi(optarg);
381 config_file = optarg;
385 rsync_port = atoi(optarg);
389 /* rprintf(FERROR,"bad option -%c\n",opt); */
396 void server_options(char **args,int *argc)
399 static char argstr[50];
400 static char bsize[30];
401 static char iotime[30];
404 args[ac++] = "--server";
407 args[ac++] = "--sender";
411 for (i=0;i<verbose;i++)
425 if (preserve_hard_links)
431 if (preserve_devices)
455 if (x != 1) args[ac++] = argstr;
457 if (block_size != BLOCK_SIZE) {
458 sprintf(bsize,"-B%d",block_size);
463 sprintf(iotime,"--timeout=%d",io_timeout);
467 if (strcmp(backup_suffix, BACKUP_SUFFIX)) {
468 args[ac++] = "--suffix";
469 args[ac++] = backup_suffix;
473 args[ac++] = "--delete";
476 args[ac++] = "--force";
479 args[ac++] = "--numeric-ids";
482 args[ac++] = "--temp-dir";