Commit | Line | Data |
---|---|---|
4afbc050 WD |
1 | This adds the option --copy-dest, which works just like --link-dest |
2 | except that identical files are copied into the destination instead | |
3 | of hard-linked. | |
4 | ||
8f72c7ae WD |
5 | --- orig/generator.c 2005-03-09 23:46:28 |
6 | +++ generator.c 2005-03-11 11:24:17 | |
d608ca23 | 7 | @@ -66,6 +66,7 @@ extern int always_checksum; |
4afbc050 WD |
8 | extern char *partial_dir; |
9 | extern char *basis_dir[]; | |
10 | extern int compare_dest; | |
11 | +extern int copy_dest; | |
12 | extern int link_dest; | |
13 | extern int whole_file; | |
14 | extern int local_server; | |
8f72c7ae | 15 | @@ -873,6 +874,8 @@ static void recv_generator(char *fname, |
251c8a01 WD |
16 | continue; |
17 | best_match = i; | |
18 | match_level = 2; | |
19 | + if (copy_dest) | |
20 | + break; | |
21 | /* FALL THROUGH */ | |
22 | case 2: | |
23 | if (!unchanged_attrs(file, &st)) | |
8f72c7ae | 24 | @@ -910,7 +913,20 @@ static void recv_generator(char *fname, |
b25262e2 | 25 | match_level = 2; |
4afbc050 | 26 | } |
e5718e56 | 27 | #endif |
b25262e2 | 28 | - if (compare_dest || (match_level && match_level < 3)) { |
e5718e56 | 29 | + if (match_level == 2) { |
4afbc050 WD |
30 | + /* Copy the file locally. */ |
31 | + if (copy_file(fnamecmpbuf, fname, file->mode) < 0) { | |
251c8a01 WD |
32 | + if (verbose) { |
33 | + rsyserr(FINFO, errno, | |
34 | + "copy_file %s => %s", | |
35 | + full_fname(fnamecmpbuf), | |
36 | + safe_fname(fname)); | |
37 | + } | |
e5718e56 | 38 | + match_level = 0; |
251c8a01 | 39 | + statret = -1; |
4afbc050 WD |
40 | + } else |
41 | + set_perms(fname, file, NULL, 0); | |
b25262e2 | 42 | + } else if (compare_dest || match_level == 1) { |
4afbc050 WD |
43 | fnamecmp = fnamecmpbuf; |
44 | fnamecmp_type = i; | |
45 | } | |
8f72c7ae | 46 | @@ -973,11 +989,9 @@ static void recv_generator(char *fname, |
d195b286 WD |
47 | return; |
48 | } | |
49 | /* Only --compare-dest gets here. */ | |
50 | - if (unchanged_attrs(file, &st)) { | |
8f72c7ae WD |
51 | - itemize(file, ndx, real_ret, &real_st, |
52 | - ITEM_NO_DEST_AND_NO_UPDATE, 0, NULL); | |
d195b286 WD |
53 | - return; |
54 | - } | |
8f72c7ae WD |
55 | + itemize(file, ndx, real_ret, &real_st, |
56 | + ITEM_NO_DEST_AND_NO_UPDATE, 0, NULL); | |
d195b286 WD |
57 | + return; |
58 | } | |
59 | ||
60 | prepare_to_open: | |
8f72c7ae | 61 | --- orig/options.c 2005-03-09 18:53:53 |
251c8a01 | 62 | +++ options.c 2005-03-02 10:05:21 |
4afbc050 WD |
63 | @@ -143,6 +143,7 @@ char *backup_dir = NULL; |
64 | char backup_dir_buf[MAXPATHLEN]; | |
65 | int rsync_port = 0; | |
66 | int compare_dest = 0; | |
67 | +int copy_dest = 0; | |
68 | int link_dest = 0; | |
69 | int basis_dir_cnt = 0; | |
8f72c7ae | 70 | char *dest_option = NULL; |
4afbc050 WD |
71 | @@ -317,6 +318,7 @@ void usage(enum logcode F) |
72 | rprintf(F," -T, --temp-dir=DIR create temporary files in directory DIR\n"); | |
73 | rprintf(F," -y, --fuzzy find similar file for basis if no dest file\n"); | |
74 | rprintf(F," --compare-dest=DIR also compare destination files relative to DIR\n"); | |
75 | + rprintf(F," --copy-dest=DIR ... and include copies of unchanged files\n"); | |
76 | rprintf(F," --link-dest=DIR hardlink to files in DIR when unchanged\n"); | |
77 | rprintf(F," -z, --compress compress file data during the transfer\n"); | |
78 | rprintf(F," -C, --cvs-exclude auto-ignore files the same way CVS does\n"); | |
79 | @@ -355,7 +357,7 @@ void usage(enum logcode F) | |
80 | } | |
81 | ||
82 | enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM, | |
83 | - OPT_FILTER, OPT_COMPARE_DEST, OPT_LINK_DEST, | |
84 | + OPT_FILTER, OPT_COMPARE_DEST, OPT_COPY_DEST, OPT_LINK_DEST, | |
85 | OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW, | |
86 | OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_TIMEOUT, OPT_MAX_SIZE, | |
87 | OPT_REFUSED_BASE = 9000}; | |
88 | @@ -424,6 +426,7 @@ static struct poptOption long_options[] | |
89 | {"timeout", 0, POPT_ARG_INT, &io_timeout, OPT_TIMEOUT, 0, 0 }, | |
90 | {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 }, | |
91 | {"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 }, | |
92 | + {"copy-dest", 0, POPT_ARG_STRING, 0, OPT_COPY_DEST, 0, 0 }, | |
93 | {"link-dest", 0, POPT_ARG_STRING, 0, OPT_LINK_DEST, 0, 0 }, | |
94 | {"fuzzy", 'y', POPT_ARG_NONE, &fuzzy_basis, 0, 0, 0 }, | |
95 | /* TODO: Should this take an optional int giving the compression level? */ | |
96 | @@ -838,6 +841,11 @@ int parse_arguments(int *argc, const cha | |
97 | return 0; | |
98 | #endif | |
99 | ||
100 | + case OPT_COPY_DEST: | |
101 | + copy_dest = 1; | |
102 | + dest_option = "--copy-dest"; | |
103 | + goto set_dest_dir; | |
104 | + | |
105 | case OPT_COMPARE_DEST: | |
106 | compare_dest = 1; | |
107 | dest_option = "--compare-dest"; | |
108 | @@ -928,9 +936,9 @@ int parse_arguments(int *argc, const cha | |
109 | return 0; | |
110 | } | |
111 | ||
112 | - if (compare_dest + link_dest > 1) { | |
113 | + if (compare_dest + copy_dest + link_dest > 1) { | |
114 | snprintf(err_buf, sizeof err_buf, | |
115 | - "You may not mix --compare-dest and --link-dest.\n"); | |
116 | + "You may not mix --compare-dest, --copy-dest, and --link-dest.\n"); | |
117 | return 0; | |
118 | } | |
119 | ||
8f72c7ae | 120 | --- orig/rsync.yo 2005-03-05 18:58:26 |
03ea3415 | 121 | +++ rsync.yo 2005-03-03 02:19:19 |
4afbc050 WD |
122 | @@ -353,6 +353,7 @@ to the detailed description below for a |
123 | -T, --temp-dir=DIR create temporary files in directory DIR | |
124 | -y, --fuzzy find similar file for basis if no dest file | |
125 | --compare-dest=DIR also compare received files relative to DIR | |
126 | + --copy-dest=DIR ... and include copies of unchanged files | |
127 | --link-dest=DIR hardlink to files in DIR when unchanged | |
128 | -z, --compress compress file data during the transfer | |
129 | -C, --cvs-exclude auto-ignore files in the same way CVS does | |
03ea3415 WD |
130 | @@ -954,13 +955,30 @@ have changed from an earlier backup. |
131 | Beginning in version 2.6.4, multiple bf(--compare-dest) directories may be | |
132 | provided, which will cause rsync to search the list in the order specified | |
133 | for an exact match. | |
134 | +If a match is found that differs only in attributes, a local copy is made | |
135 | +and the attributes updated. | |
136 | If a match is not found, a basis file from one of the em(DIR)s will be | |
137 | selected to try to speed up the transfer. | |
4afbc050 WD |
138 | |
139 | If em(DIR) is a relative path, it is relative to the destination directory. | |
140 | -See also bf(--link-dest). | |
141 | +See also bf(--copy-dest) and bf(--link-dest). | |
142 | ||
143 | -dit(bf(--link-dest=DIR)) This option behaves like bf(--compare-dest), but | |
144 | +dit(bf(--copy-dest=DIR)) This option behaves like bf(--compare-dest), but | |
145 | +rsync will also copy unchanged files found in em(DIR) to the destination | |
03ea3415 | 146 | +directory using a local copy. This is |
4afbc050 WD |
147 | +useful for doing transfers to a new destination while leaving existing |
148 | +files intact, and then doing a flash-cutover when all files have been | |
149 | +successfully transferred. | |
150 | + | |
03ea3415 WD |
151 | +Multiple bf(--copy-dest) directories may be provided, which will cause |
152 | +rsync to search the list in the order specified for an unchanged file. | |
153 | +If a match is not found, a basis file from one of the em(DIR)s will be | |
154 | +selected to try to speed up the transfer. | |
155 | + | |
4afbc050 WD |
156 | +If em(DIR) is a relative path, it is relative to the destination directory. |
157 | +See also bf(--compare-dest) and bf(--link-dest). | |
158 | + | |
159 | +dit(bf(--link-dest=DIR)) This option behaves like bf(--copy-dest), but | |
160 | unchanged files are hard linked from em(DIR) to the destination directory. | |
161 | The files must be identical in all preserved attributes (e.g. permissions, | |
162 | possibly ownership) in order for the files to be linked together. | |
03ea3415 WD |
163 | @@ -971,11 +989,13 @@ quote(tt( rsync -av --link-dest=$PWD/pr |
164 | Beginning in version 2.6.4, multiple bf(--link-dest) directories may be | |
165 | provided, which will cause rsync to search the list in the order specified | |
166 | for an exact match. | |
167 | +If a match is found that differs only in attributes, a local copy is made | |
168 | +and the attributes updated. | |
169 | If a match is not found, a basis file from one of the em(DIR)s will be | |
170 | selected to try to speed up the transfer. | |
4afbc050 WD |
171 | |
172 | If em(DIR) is a relative path, it is relative to the destination directory. | |
173 | -See also bf(--compare-dest). | |
174 | +See also bf(--compare-dest) and bf(--copy-dest). | |
175 | ||
176 | Note that rsync versions prior to 2.6.1 had a bug that could prevent | |
177 | bf(--link-dest) from working properly for a non-root user when bf(-o) was specified | |
8f72c7ae | 178 | --- orig/testsuite/compare-dest.test 2005-02-26 19:49:59 |
4afbc050 WD |
179 | +++ testsuite/compare-dest.test 2005-03-01 15:57:27 |
180 | @@ -31,9 +31,9 @@ $RSYNC -av --exclude=/text --exclude=etc | |
181 | checkit "$RSYNC -avv --no-whole-file \ | |
182 | --compare-dest=\"$alt1dir\" --compare-dest=\"$alt2dir\" \ | |
183 | \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir" | |
184 | -#checkit "$RSYNC -avv --no-whole-file \ | |
185 | -# --copy-dest=\"$alt1dir\" --copy-dest=\"$alt2dir\" \ | |
186 | -# \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir" | |
187 | +checkit "$RSYNC -avv --no-whole-file \ | |
188 | + --copy-dest=\"$alt1dir\" --copy-dest=\"$alt2dir\" \ | |
189 | + \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir" | |
190 | ||
191 | # The script would have aborted on error, so getting here means we've won. | |
192 | exit 0 |