1 /* -*- c-file-style: "linux" -*-
3 Copyright (C) 1998-2000 by Andrew Tridgell
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /* options parsing code */
28 int preserve_links
= 0;
29 int preserve_hard_links
= 0;
30 int preserve_perms
= 0;
31 int preserve_devices
= 0;
34 int preserve_times
= 0;
41 int delete_excluded
=0;
42 int one_file_system
=0;
63 int copy_unsafe_links
=0;
64 int block_size
=BLOCK_SIZE
;
78 char *backup_suffix
= BACKUP_SUFFIX
;
80 char *compare_dest
= NULL
;
81 char *config_file
= RSYNCD_CONF
;
82 char *shell_cmd
= NULL
;
83 char *log_format
= NULL
;
84 char *password_file
= NULL
;
85 char *rsync_path
= RSYNC_NAME
;
86 char *backup_dir
= NULL
;
87 int rsync_port
= RSYNC_PORT
;
91 int always_checksum
= 0;
94 static int modify_window_set
;
97 struct in_addr socket_address
= {INADDR_ANY
};
100 static void print_rsync_version(void)
102 char const *got_socketpair
= "no ";
104 #ifdef HAVE_SOCKETPAIR
108 rprintf(FINFO
, "rsync version %s protocol version %d\n",
109 VERSION
, PROTOCOL_VERSION
);
110 rprintf(FINFO
, "Configuration: %d-bit files, %ssocketpairs\n\n",
113 rprintf(FINFO
, "Written by Andrew Tridgell and Paul Mackerras "
114 "<http://rsync.samba.org/>\n\n");
116 rprintf(FINFO
, "WARNING: no 64-bit integers on this platform!\n");
121 void usage(enum logcode F
)
123 rprintf(F
,"rsync version %s Copyright Andrew Tridgell and Paul Mackerras\n\n",
126 rprintf(F
, "WARNING: no 64-bit integers on this platform!\n");
129 rprintf(F
,"rsync is a file transfer program capable of efficient remote update\nvia a fast differencing algorithm.\n\n");
131 rprintf(F
,"Usage: rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST\n");
132 rprintf(F
," or rsync [OPTION]... [USER@]HOST:SRC DEST\n");
133 rprintf(F
," or rsync [OPTION]... SRC [SRC]... DEST\n");
134 rprintf(F
," or rsync [OPTION]... [USER@]HOST::SRC [DEST]\n");
135 rprintf(F
," or rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST\n");
136 rprintf(F
," or rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]\n");
137 rprintf(F
,"SRC on single-colon remote HOST will be expanded by remote shell\n");
138 rprintf(F
,"SRC on server remote HOST may contain shell wildcards or multiple\n");
139 rprintf(F
," sources separated by space as long as they have same top-level\n");
140 rprintf(F
,"\nOptions\n");
141 rprintf(F
," -v, --verbose increase verbosity\n");
142 rprintf(F
," -q, --quiet decrease verbosity\n");
143 rprintf(F
," -c, --checksum always checksum\n");
144 rprintf(F
," -a, --archive archive mode\n");
145 rprintf(F
," -r, --recursive recurse into directories\n");
146 rprintf(F
," -R, --relative use relative path names\n");
147 rprintf(F
," -b, --backup make backups (default %s suffix)\n",BACKUP_SUFFIX
);
148 rprintf(F
," --backup-dir make backups into this directory\n");
149 rprintf(F
," --suffix=SUFFIX override backup suffix\n");
150 rprintf(F
," -u, --update update only (don't overwrite newer files)\n");
151 rprintf(F
," -l, --links preserve soft links\n");
152 rprintf(F
," -L, --copy-links treat soft links like regular files\n");
153 rprintf(F
," --copy-unsafe-links copy links outside the source tree\n");
154 rprintf(F
," --safe-links ignore links outside the destination tree\n");
155 rprintf(F
," -H, --hard-links preserve hard links\n");
156 rprintf(F
," -p, --perms preserve permissions\n");
157 rprintf(F
," -o, --owner preserve owner (root only)\n");
158 rprintf(F
," -g, --group preserve group\n");
159 rprintf(F
," -D, --devices preserve devices (root only)\n");
160 rprintf(F
," -t, --times preserve times\n");
161 rprintf(F
," -S, --sparse handle sparse files efficiently\n");
162 rprintf(F
," -n, --dry-run show what would have been transferred\n");
163 rprintf(F
," -W, --whole-file copy whole files, no incremental checks\n");
164 rprintf(F
," -x, --one-file-system don't cross filesystem boundaries\n");
165 rprintf(F
," -B, --block-size=SIZE checksum blocking size (default %d)\n",BLOCK_SIZE
);
166 rprintf(F
," -e, --rsh=COMMAND specify rsh replacement\n");
167 rprintf(F
," --rsync-path=PATH specify path to rsync on the remote machine\n");
168 rprintf(F
," -C, --cvs-exclude auto ignore files in the same way CVS does\n");
169 rprintf(F
," --existing only update files that already exist\n");
170 rprintf(F
," --delete delete files that don't exist on the sending side\n");
171 rprintf(F
," --delete-excluded also delete excluded files on the receiving side\n");
172 rprintf(F
," --delete-after delete after transferring, not before\n");
173 rprintf(F
," --ignore-errors delete even if there are IO errors\n");
174 rprintf(F
," --max-delete=NUM don't delete more than NUM files\n");
175 rprintf(F
," --partial keep partially transferred files\n");
176 rprintf(F
," --force force deletion of directories even if not empty\n");
177 rprintf(F
," --numeric-ids don't map uid/gid values by user/group name\n");
178 rprintf(F
," --timeout=TIME set IO timeout in seconds\n");
179 rprintf(F
," -I, --ignore-times don't exclude files that match length and time\n");
180 rprintf(F
," --size-only only use file size when determining if a file should be transferred\n");
181 rprintf(F
," --modify-window=NUM Timestamp window (seconds) for file match (default=%d)\n",modify_window
);
182 rprintf(F
," -T --temp-dir=DIR create temporary files in directory DIR\n");
183 rprintf(F
," --compare-dest=DIR also compare destination files relative to DIR\n");
184 rprintf(F
," -P equivalent to --partial --progress\n");
185 rprintf(F
," -z, --compress compress file data\n");
186 rprintf(F
," --exclude=PATTERN exclude files matching PATTERN\n");
187 rprintf(F
," --exclude-from=FILE exclude patterns listed in FILE\n");
188 rprintf(F
," --include=PATTERN don't exclude files matching PATTERN\n");
189 rprintf(F
," --include-from=FILE don't exclude patterns listed in FILE\n");
190 rprintf(F
," --version print version number\n");
191 rprintf(F
," --daemon run as a rsync daemon\n");
192 rprintf(F
," --address bind to the specified address\n");
193 rprintf(F
," --config=FILE specify alternate rsyncd.conf file\n");
194 rprintf(F
," --port=PORT specify alternate rsyncd port number\n");
195 rprintf(F
," --blocking-io use blocking IO for the remote shell\n");
196 rprintf(F
," --stats give some file transfer stats\n");
197 rprintf(F
," --progress show progress during transfer\n");
198 rprintf(F
," --log-format=FORMAT log file transfers using specified format\n");
199 rprintf(F
," --password-file=FILE get password from FILE\n");
200 rprintf(F
," --bwlimit=KBPS limit I/O bandwidth, KBytes per second\n");
201 rprintf(F
," -h, --help show this help screen\n");
205 rprintf(F
,"\nPlease see the rsync(1) and rsyncd.conf(5) man pages for full documentation\n");
206 rprintf(F
,"See http://rsync.samba.org/ for updates and bug reports\n");
209 enum {OPT_VERSION
, OPT_SUFFIX
, OPT_SENDER
, OPT_SERVER
, OPT_EXCLUDE
,
210 OPT_EXCLUDE_FROM
, OPT_DELETE
, OPT_DELETE_EXCLUDED
, OPT_NUMERIC_IDS
,
211 OPT_RSYNC_PATH
, OPT_FORCE
, OPT_TIMEOUT
, OPT_DAEMON
, OPT_CONFIG
, OPT_PORT
,
212 OPT_INCLUDE
, OPT_INCLUDE_FROM
, OPT_STATS
, OPT_PARTIAL
, OPT_PROGRESS
,
213 OPT_COPY_UNSAFE_LINKS
, OPT_SAFE_LINKS
, OPT_COMPARE_DEST
,
214 OPT_LOG_FORMAT
, OPT_PASSWORD_FILE
, OPT_SIZE_ONLY
, OPT_ADDRESS
,
215 OPT_DELETE_AFTER
, OPT_EXISTING
, OPT_MAX_DELETE
, OPT_BACKUP_DIR
,
216 OPT_IGNORE_ERRORS
, OPT_BWLIMIT
, OPT_BLOCKING_IO
,
219 static char *short_options
= "oblLWHpguDCtcahvqrRIxnSe:B:T:zP";
221 static struct option long_options
[] = {
222 {"version", 0, 0, OPT_VERSION
},
223 {"server", 0, 0, OPT_SERVER
},
224 {"sender", 0, 0, OPT_SENDER
},
225 {"existing", 0, 0, OPT_EXISTING
},
226 {"delete", 0, 0, OPT_DELETE
},
227 {"delete-excluded", 0, 0, OPT_DELETE_EXCLUDED
},
228 {"force", 0, 0, OPT_FORCE
},
229 {"numeric-ids", 0, 0, OPT_NUMERIC_IDS
},
230 {"exclude", 1, 0, OPT_EXCLUDE
},
231 {"exclude-from",1, 0, OPT_EXCLUDE_FROM
},
232 {"include", 1, 0, OPT_INCLUDE
},
233 {"include-from",1, 0, OPT_INCLUDE_FROM
},
234 {"rsync-path", 1, 0, OPT_RSYNC_PATH
},
235 {"password-file", 1, 0, OPT_PASSWORD_FILE
},
236 {"one-file-system",0, 0, 'x'},
237 {"ignore-times",0, 0, 'I'},
238 {"size-only", 0, 0, OPT_SIZE_ONLY
},
239 {"modify-window",1, 0, OPT_MODIFY_WINDOW
},
241 {"dry-run", 0, 0, 'n'},
242 {"sparse", 0, 0, 'S'},
243 {"cvs-exclude", 0, 0, 'C'},
244 {"archive", 0, 0, 'a'},
245 {"checksum", 0, 0, 'c'},
246 {"backup", 0, 0, 'b'},
247 {"update", 0, 0, 'u'},
248 {"verbose", 0, 0, 'v'},
249 {"quiet", 0, 0, 'q'},
250 {"recursive", 0, 0, 'r'},
251 {"relative", 0, 0, 'R'},
252 {"devices", 0, 0, 'D'},
253 {"perms", 0, 0, 'p'},
254 {"links", 0, 0, 'l'},
255 {"copy-links", 0, 0, 'L'},
256 {"copy-unsafe-links", 0, 0, OPT_COPY_UNSAFE_LINKS
},
257 {"safe-links", 0, 0, OPT_SAFE_LINKS
},
258 {"whole-file", 0, 0, 'W'},
259 {"hard-links", 0, 0, 'H'},
260 {"owner", 0, 0, 'o'},
261 {"group", 0, 0, 'g'},
262 {"times", 0, 0, 't'},
264 {"suffix", 1, 0, OPT_SUFFIX
},
265 {"block-size", 1, 0, 'B'},
266 {"timeout", 1, 0, OPT_TIMEOUT
},
267 {"temp-dir", 1, 0, 'T'},
268 {"compare-dest", 1, 0, OPT_COMPARE_DEST
},
269 {"compress", 0, 0, 'z'},
270 {"daemon", 0, 0, OPT_DAEMON
},
271 {"stats", 0, 0, OPT_STATS
},
272 {"progress", 0, 0, OPT_PROGRESS
},
273 {"partial", 0, 0, OPT_PARTIAL
},
274 {"delete-after",0, 0, OPT_DELETE_AFTER
},
275 {"ignore-errors",0, 0, OPT_IGNORE_ERRORS
},
276 {"blocking-io" ,0, 0, OPT_BLOCKING_IO
},
277 {"config", 1, 0, OPT_CONFIG
},
278 {"port", 1, 0, OPT_PORT
},
279 {"log-format", 1, 0, OPT_LOG_FORMAT
},
280 {"bwlimit", 1, 0, OPT_BWLIMIT
},
281 {"address", 1, 0, OPT_ADDRESS
},
282 {"max-delete", 1, 0, OPT_MAX_DELETE
},
283 {"backup-dir", 1, 0, OPT_BACKUP_DIR
},
287 static char err_buf
[100];
289 void option_error(void)
292 rprintf(FLOG
,"%s", err_buf
);
293 rprintf(FERROR
,"%s", err_buf
);
295 rprintf(FLOG
,"Error parsing options - unsupported option?\n");
296 rprintf(FERROR
,"Error parsing options - unsupported option?\n");
298 exit_cleanup(RERR_UNSUPPORTED
);
301 /* check to see if we should refuse this option */
302 static int check_refuse_options(char *ref
, int opt
)
308 for (i
=0; long_options
[i
].name
; i
++) {
309 if (long_options
[i
].val
== opt
) break;
312 if (!long_options
[i
].name
) return 0;
314 name
= long_options
[i
].name
;
317 while ((p
= strstr(ref
,name
))) {
318 if ((p
==ref
|| p
[-1]==' ') &&
319 (p
[len
] == ' ' || p
[len
] == 0)) {
320 slprintf(err_buf
,sizeof(err_buf
),
321 "The '%s' option is not supported by this server\n", name
);
330 int parse_arguments(int argc
, char *argv
[], int frommain
)
334 char *ref
= lp_refuse_options(module_id
);
336 while ((opt
= getopt_long(argc
, argv
,
337 short_options
, long_options
, &option_index
))
341 if (check_refuse_options(ref
, opt
)) return 0;
346 print_rsync_version();
350 backup_suffix
= optarg
;
357 case OPT_PASSWORD_FILE
:
358 password_file
=optarg
;
369 case OPT_MODIFY_WINDOW
:
370 modify_window
= atoi(optarg
);
371 modify_window_set
= 1;
386 case OPT_DELETE_AFTER
:
390 case OPT_DELETE_EXCLUDED
:
399 case OPT_NUMERIC_IDS
:
404 add_exclude(optarg
, 0);
408 add_exclude(optarg
, 1);
411 case OPT_EXCLUDE_FROM
:
412 add_exclude_file(optarg
,1, 0);
415 case OPT_INCLUDE_FROM
:
416 add_exclude_file(optarg
,1, 1);
419 case OPT_COPY_UNSAFE_LINKS
:
464 #if SUPPORT_HARD_LINKS
465 preserve_hard_links
=1;
467 slprintf(err_buf
,sizeof(err_buf
),"hard links are not supported on this server\n");
468 rprintf(FERROR
,"ERROR: hard links not supported on this platform\n");
502 if (frommain
) quiet
++;
524 exit_cleanup(RERR_SYNTAX
);
542 block_size
= atoi(optarg
);
546 max_delete
= atoi(optarg
);
550 io_timeout
= atoi(optarg
);
557 case OPT_COMPARE_DEST
:
558 compare_dest
= optarg
;
581 case OPT_IGNORE_ERRORS
:
585 case OPT_BLOCKING_IO
:
595 config_file
= optarg
;
599 rsync_port
= atoi(optarg
);
607 bwlimit
= atoi(optarg
);
613 if ((ia
= ip_address(optarg
))) {
614 socket_address
= *ia
;
624 /* FIXME: This can be confusing when the error message
625 * is coming from a remote server which has an older
626 * rsync version than the local version. The user
627 * sees the option documented in the local --help, but
628 * then the program seems to refuse to execute it. So
629 * perhaps the message should give the hostname or
632 * In rsync 3.x, it might be nice if options which
633 * only affect one end didn't have to bother the
635 slprintf(err_buf
,sizeof(err_buf
),"unrecognised option\n");
643 /* need to pass all the valid options from the client to the server */
645 void server_options(char **args
,int *argc
)
648 static char argstr
[50];
649 static char bsize
[30];
650 static char iotime
[30];
651 static char mdelete
[30];
652 static char mwindow
[30];
657 args
[ac
++] = "--server";
660 args
[ac
++] = "--sender";
664 for (i
=0;i
<verbose
;i
++)
667 /* the -q option is intentionally left out */
680 if (preserve_hard_links
)
686 if (preserve_devices
)
709 /* this is a complete hack - blame Rusty
711 this is a hack to make the list_only (remote file list)
713 if (list_only
&& !recurse
)
718 if (x
!= 1) args
[ac
++] = argstr
;
720 if (block_size
!= BLOCK_SIZE
) {
721 slprintf(bsize
,sizeof(bsize
),"-B%d",block_size
);
725 if (max_delete
&& am_sender
) {
726 slprintf(mdelete
,sizeof(mdelete
),"--max-delete=%d",max_delete
);
727 args
[ac
++] = mdelete
;
731 slprintf(iotime
,sizeof(iotime
),"--timeout=%d",io_timeout
);
736 slprintf(bw
,sizeof(bw
),"--bwlimit=%d",bwlimit
);
740 if (strcmp(backup_suffix
, BACKUP_SUFFIX
)) {
741 args
[ac
++] = "--suffix";
742 args
[ac
++] = backup_suffix
;
745 if (delete_mode
&& !delete_excluded
)
746 args
[ac
++] = "--delete";
749 args
[ac
++] = "--delete-excluded";
752 args
[ac
++] = "--size-only";
754 if (modify_window_set
) {
755 slprintf(mwindow
,sizeof(mwindow
),"--modify-window=%d",
757 args
[ac
++] = mwindow
;
761 args
[ac
++] = "--partial";
764 args
[ac
++] = "--force";
767 args
[ac
++] = "--delete-after";
770 args
[ac
++] = "--ignore-errors";
772 if (copy_unsafe_links
)
773 args
[ac
++] = "--copy-unsafe-links";
776 args
[ac
++] = "--safe-links";
779 args
[ac
++] = "--numeric-ids";
781 if (only_existing
&& am_sender
)
782 args
[ac
++] = "--existing";
785 args
[ac
++] = "--temp-dir";
789 if (backup_dir
&& am_sender
) {
790 /* only the receiver needs this option, if we are the sender
791 * then we need to send it to the receiver.
793 args
[ac
++] = "--backup-dir";
794 args
[ac
++] = backup_dir
;
797 if (compare_dest
&& am_sender
) {
798 /* the server only needs this option if it is not the sender,
799 * and it may be an older version that doesn't know this
800 * option, so don't send it if client is the sender.
802 args
[ac
++] = "--compare-dest";
803 args
[ac
++] = compare_dest
;