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;
59 int block_size=BLOCK_SIZE;
61 char *backup_suffix = BACKUP_SUFFIX;
63 char *config_file = RSYNCD_CONF;
64 char *shell_cmd = NULL;
66 char *rsync_path = RSYNC_NAME;
67 int rsync_port = RSYNC_PORT;
70 int always_checksum = 0;
75 rprintf(F,"rsync version %s Copyright Andrew Tridgell and Paul Mackerras\n\n",
77 rprintf(F,"Usage:\t%s [options] src user@host:dest\nOR",RSYNC_NAME);
78 rprintf(F,"\t%s [options] user@host:src dest\n\n",RSYNC_NAME);
79 rprintf(F,"Options:\n");
80 rprintf(F,"-v, --verbose increase verbosity\n");
81 rprintf(F,"-c, --checksum always checksum\n");
82 rprintf(F,"-a, --archive archive mode (same as -rlptDog)\n");
83 rprintf(F,"-r, --recursive recurse into directories\n");
84 rprintf(F,"-R, --relative use relative path names\n");
85 rprintf(F,"-b, --backup make backups (default ~ extension)\n");
86 rprintf(F,"-u, --update update only (don't overwrite newer files)\n");
87 rprintf(F,"-l, --links preserve soft links\n");
88 rprintf(F,"-L, --copy-links treat soft links like regular files\n");
89 rprintf(F,"-H, --hard-links preserve hard links\n");
90 rprintf(F,"-p, --perms preserve permissions\n");
91 rprintf(F,"-o, --owner preserve owner (root only)\n");
92 rprintf(F,"-g, --group preserve group\n");
93 rprintf(F,"-D, --devices preserve devices (root only)\n");
94 rprintf(F,"-t, --times preserve times\n");
95 rprintf(F,"-S, --sparse handle sparse files efficiently\n");
96 rprintf(F,"-n, --dry-run show what would have been transferred\n");
97 rprintf(F,"-W, --whole-file copy whole files, no incremental checks\n");
98 rprintf(F,"-x, --one-file-system don't cross filesystem boundaries\n");
99 rprintf(F,"-B, --block-size SIZE checksum blocking size\n");
100 rprintf(F,"-e, --rsh COMMAND specify rsh replacement\n");
101 rprintf(F," --rsync-path PATH specify path to rsync on the remote machine\n");
102 rprintf(F,"-C, --cvs-exclude auto ignore files in the same way CVS does\n");
103 rprintf(F," --delete delete files that don't exist on the sending side\n");
104 rprintf(F," --force force deletion of directories even if not empty\n");
105 rprintf(F," --numeric-ids don't map uid/gid values by user/group name\n");
106 rprintf(F," --timeout TIME set IO timeout in seconds\n");
107 rprintf(F,"-I, --ignore-times don't exclude files that match length and time\n");
108 rprintf(F,"-T --temp-dir DIR create temporary files in directory DIR\n");
109 rprintf(F,"-z, --compress compress file data\n");
110 rprintf(F," --exclude FILE exclude file FILE\n");
111 rprintf(F," --exclude-from FILE exclude files listed in FILE\n");
112 rprintf(F," --suffix SUFFIX override backup suffix\n");
113 rprintf(F," --version print version number\n");
114 rprintf(F," --daemon run as a rsync daemon\n");
115 rprintf(F," --config FILE specify alternate rsyncd.conf file\n");
116 rprintf(F," --port PORT specify alternate rsyncd port number\n");
119 rprintf(F,"the backup suffix defaults to %s\n",BACKUP_SUFFIX);
120 rprintf(F,"the block size defaults to %d\n",BLOCK_SIZE);
123 enum {OPT_VERSION,OPT_SUFFIX,OPT_SENDER,OPT_SERVER,OPT_EXCLUDE,
124 OPT_EXCLUDE_FROM,OPT_DELETE,OPT_NUMERIC_IDS,OPT_RSYNC_PATH,
125 OPT_FORCE,OPT_TIMEOUT,OPT_DAEMON,OPT_CONFIG,OPT_PORT};
127 static char *short_options = "oblLWHpguDCtcahvrRIxnSe:B:T:z";
129 static struct option long_options[] = {
130 {"version", 0, 0, OPT_VERSION},
131 {"server", 0, 0, OPT_SERVER},
132 {"sender", 0, 0, OPT_SENDER},
133 {"delete", 0, 0, OPT_DELETE},
134 {"force", 0, 0, OPT_FORCE},
135 {"numeric-ids", 0, 0, OPT_NUMERIC_IDS},
136 {"exclude", 1, 0, OPT_EXCLUDE},
137 {"exclude-from",1, 0, OPT_EXCLUDE_FROM},
138 {"rsync-path", 1, 0, OPT_RSYNC_PATH},
139 {"one-file-system",0, 0, 'x'},
140 {"ignore-times",0, 0, 'I'},
142 {"dry-run", 0, 0, 'n'},
143 {"sparse", 0, 0, 'S'},
144 {"cvs-exclude", 0, 0, 'C'},
145 {"archive", 0, 0, 'a'},
146 {"checksum", 0, 0, 'c'},
147 {"backup", 0, 0, 'b'},
148 {"update", 0, 0, 'u'},
149 {"verbose", 0, 0, 'v'},
150 {"recursive", 0, 0, 'r'},
151 {"relative", 0, 0, 'R'},
152 {"devices", 0, 0, 'D'},
153 {"perms", 0, 0, 'p'},
154 {"links", 0, 0, 'l'},
155 {"copy-links", 0, 0, 'L'},
156 {"whole-file", 0, 0, 'W'},
157 {"hard-links", 0, 0, 'H'},
158 {"owner", 0, 0, 'o'},
159 {"group", 0, 0, 'g'},
160 {"times", 0, 0, 't'},
162 {"suffix", 1, 0, OPT_SUFFIX},
163 {"block-size", 1, 0, 'B'},
164 {"timeout", 1, 0, OPT_TIMEOUT},
165 {"temp-dir", 1, 0, 'T'},
166 {"compress", 0, 0, 'z'},
167 {"daemon", 0, 0, OPT_DAEMON},
168 {"config", 1, 0, OPT_CONFIG},
169 {"port", 1, 0, OPT_PORT},
172 void parse_arguments(int argc, char *argv[])
177 while ((opt = getopt_long(argc, argv,
178 short_options, long_options, &option_index))
183 printf("rsync version %s protocol version %d\n",
184 VERSION,PROTOCOL_VERSION);
188 backup_suffix = optarg;
211 case OPT_NUMERIC_IDS:
219 case OPT_EXCLUDE_FROM:
220 add_exclude_file(optarg,1);
260 #if SUPPORT_HARD_LINKS
261 preserve_hard_links=1;
263 rprintf(FERROR,"ERROR: hard links not supported on this platform\n");
335 block_size = atoi(optarg);
339 io_timeout = atoi(optarg);
355 config_file = optarg;
359 rsync_port = atoi(optarg);
363 /* rprintf(FERROR,"bad option -%c\n",opt); */
370 void server_options(char **args,int *argc)
373 static char argstr[50];
374 static char bsize[30];
375 static char iotime[30];
378 args[ac++] = "--server";
381 args[ac++] = "--sender";
385 for (i=0;i<verbose;i++)
399 if (preserve_hard_links)
405 if (preserve_devices)
429 if (x != 1) args[ac++] = argstr;
431 if (block_size != BLOCK_SIZE) {
432 sprintf(bsize,"-B%d",block_size);
437 sprintf(iotime,"--timeout=%d",io_timeout);
441 if (strcmp(backup_suffix, BACKUP_SUFFIX)) {
442 args[ac++] = "--suffix";
443 args[ac++] = backup_suffix;
447 args[ac++] = "--delete";
450 args[ac++] = "--force";
453 args[ac++] = "--numeric-ids";
456 args[ac++] = "--temp-dir";