1 This patches creates two new command line options as follows:
5 The backup-dir-dels and suffix-dels options give the ability to store
6 backup of removed files on the receiver in different directories or with
7 different suffix than the backup of files that have been changed but that
8 are still on the source drive. Both commands can be combined.
10 The default behaviour if one or both of the options are not specified
11 is the previous behaviour, both backups use the same directory or
16 To use this patch, run these commands for a successful build:
18 patch -p1 <patches/backup-dir-dels.diff
19 ./configure (optional if already run)
27 extern int backup_dir_len;
28 +extern int backup_dir_dels_len;
29 extern unsigned int backup_dir_remainder;
30 +extern unsigned int backup_dir_dels_remainder;
31 extern char backup_dir_buf[MAXPATHLEN];
32 +extern char backup_dir_dels_buf[MAXPATHLEN];
33 extern char *backup_suffix;
34 +extern char *backup_suffix_dels;
35 extern char *backup_dir;
36 +extern char *backup_dir_dels;
39 extern int preserve_devices;
40 @@ -34,6 +39,8 @@ extern int preserve_specials;
41 extern int preserve_links;
42 extern int safe_symlinks;
46 /* make a complete pathname for backup file */
47 char *get_backup_name(char *fname)
49 @@ -51,11 +58,28 @@ char *get_backup_name(char *fname)
53 +static char *get_delete_name(char *fname)
55 + if (backup_dir_dels) {
56 + if (stringjoin(backup_dir_dels_buf + backup_dir_dels_len, backup_dir_dels_remainder,
57 + fname, backup_suffix_dels, NULL) < backup_dir_dels_remainder)
58 + return backup_dir_dels_buf;
60 + if (stringjoin(backup_dir_dels_buf, MAXPATHLEN,
61 + fname, backup_suffix_dels, NULL) < MAXPATHLEN)
62 + return backup_dir_dels_buf;
65 + rprintf(FERROR, "delete filename too long\n");
69 /* simple backup creates a backup with a suffix in the same directory */
70 static int make_simple_backup(char *fname)
73 - char *fnamebak = get_backup_name(fname);
74 + char *fnamebak = deleting ? get_delete_name(fname)
75 + : get_backup_name(fname);
79 @@ -95,7 +119,8 @@ path
80 static int make_bak_dir(char *fullpath)
83 - char *rel = fullpath + backup_dir_len;
84 + int dir_len = deleting ? backup_dir_dels_len : backup_dir_len;
85 + char *rel = fullpath + dir_len;
86 char *end = rel + strlen(rel);
89 @@ -183,7 +208,8 @@ static int keep_backup(char *fname)
90 if (!(file = make_file(fname, NULL, NULL, 0, NO_FILTERS)))
91 return 1; /* the file could have disappeared */
93 - if (!(buf = get_backup_name(fname)))
94 + buf = deleting ? get_delete_name(fname) : get_backup_name(fname);
98 /* Check to see if this is a device file, or link */
99 @@ -278,3 +304,13 @@ int make_backup(char *fname)
100 return keep_backup(fname);
101 return make_simple_backup(fname);
104 +/* backup switch routine called only when backing-up removed file */
105 +int safe_delete(char *fname)
109 + ret = make_backup(fname);
115 @@ -90,6 +90,9 @@ extern dev_t filesystem_dev;
116 extern char *backup_dir;
117 extern char *backup_suffix;
118 extern int backup_suffix_len;
119 +extern char *backup_dir_dels;
120 +extern char *backup_suffix_dels;
121 +extern int backup_suffix_dels_len;
122 extern struct file_list *the_file_list;
123 extern struct filter_list_struct server_filter_list;
125 @@ -100,10 +103,14 @@ static int deletion_count = 0; /* used t
126 #define DEL_TERSE (1<<3)
129 +/* Function now compares both backup_suffix and backup_suffix_dels. */
130 static int is_backup_file(char *fn)
132 int k = strlen(fn) - backup_suffix_len;
133 - return k > 0 && strcmp(fn+k, backup_suffix) == 0;
134 + if (k > 0 && strcmp(fn+k, backup_suffix) == 0)
136 + k += backup_suffix_len - backup_suffix_dels_len;
137 + return k > 0 && strcmp(fn+k, backup_suffix_dels) == 0;
141 @@ -124,8 +131,8 @@ static int delete_item(char *fname, int
142 if (!S_ISDIR(mode)) {
143 if (max_delete && ++deletion_count > max_delete)
145 - if (make_backups && (backup_dir || !is_backup_file(fname)))
146 - ok = make_backup(fname);
147 + if (make_backups && (backup_dir_dels || !is_backup_file(fname)))
148 + ok = safe_delete(fname);
150 ok = robust_unlink(fname) == 0;
152 @@ -147,9 +154,9 @@ static int delete_item(char *fname, int
153 || (dry_run && zap_dir)) {
156 - } else if (make_backups && !backup_dir && !is_backup_file(fname)
157 + } else if (make_backups && !backup_dir_dels && !is_backup_file(fname)
158 && !(flags & DEL_FORCE_RECURSE))
159 - ok = make_backup(fname);
160 + ok = safe_delete(fname);
162 ok = do_rmdir(fname) == 0;
166 @@ -138,10 +138,14 @@ int no_detach
169 int backup_dir_len = 0;
170 +int backup_dir_dels_len = 0;
171 int backup_suffix_len;
172 +int backup_suffix_dels_len;
173 unsigned int backup_dir_remainder;
174 +unsigned int backup_dir_dels_remainder;
176 char *backup_suffix = NULL;
177 +char *backup_suffix_dels = NULL;
179 char *partial_dir = NULL;
180 char *basis_dir[MAX_BASIS_DIRS+1];
181 @@ -153,7 +157,9 @@ char *stdout_format = NULL;
182 char *password_file = NULL;
183 char *rsync_path = RSYNC_PATH;
184 char *backup_dir = NULL;
185 +char *backup_dir_dels = NULL;
186 char backup_dir_buf[MAXPATHLEN];
187 +char backup_dir_dels_buf[MAXPATHLEN];
188 char *sockopts = NULL;
190 int compare_dest = 0;
191 @@ -292,6 +298,8 @@ void usage(enum logcode F)
192 rprintf(F," -b, --backup make backups (see --suffix & --backup-dir)\n");
193 rprintf(F," --backup-dir=DIR make backups into hierarchy based in DIR\n");
194 rprintf(F," --suffix=SUFFIX set backup suffix (default %s w/o --backup-dir)\n",BACKUP_SUFFIX);
195 + rprintf(F," --backup-dir-dels make backups of removed files into current dir\n");
196 + rprintf(F," --suffix-dels=SUFFIX set removed-files suffix (defaults to --suffix)\n");
197 rprintf(F," -u, --update skip files that are newer on the receiver\n");
198 rprintf(F," --inplace update destination files in-place (SEE MAN PAGE)\n");
199 rprintf(F," --append append data onto shorter files\n");
200 @@ -518,7 +526,9 @@ static struct poptOption long_options[]
201 {"bwlimit", 0, POPT_ARG_INT, &bwlimit, 0, 0, 0 },
202 {"backup", 'b', POPT_ARG_NONE, &make_backups, 0, 0, 0 },
203 {"backup-dir", 0, POPT_ARG_STRING, &backup_dir, 0, 0, 0 },
204 + {"backup-dir-dels", 0, POPT_ARG_STRING, &backup_dir_dels, 0, 0, 0 },
205 {"suffix", 0, POPT_ARG_STRING, &backup_suffix, 0, 0, 0 },
206 + {"suffix-dels", 0, POPT_ARG_STRING, &backup_suffix_dels, 0, 0, 0 },
207 {"list-only", 0, POPT_ARG_VAL, &list_only, 2, 0, 0 },
208 {"read-batch", 0, POPT_ARG_STRING, &batch_name, OPT_READ_BATCH, 0, 0 },
209 {"write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_WRITE_BATCH, 0, 0 },
210 @@ -1232,6 +1242,8 @@ int parse_arguments(int *argc, const cha
211 tmpdir = sanitize_path(NULL, tmpdir, NULL, 0, NULL);
213 backup_dir = sanitize_path(NULL, backup_dir, NULL, 0, NULL);
214 + if (backup_dir_dels)
215 + backup_dir_dels = sanitize_path(NULL, backup_dir_dels, NULL, 0, NULL);
217 if (server_filter_list.head && !am_sender) {
218 struct filter_list_struct *elp = &server_filter_list;
219 @@ -1253,6 +1265,14 @@ int parse_arguments(int *argc, const cha
223 + /* Clean backup_dir_dels same as for backup_dir */
224 + if (backup_dir_dels) {
225 + if (!*backup_dir_dels)
226 + goto options_rejected;
227 + clean_fname(backup_dir_dels, 1);
228 + if (check_filter(elp, backup_dir_dels, 1) < 0)
229 + goto options_rejected;
234 @@ -1264,6 +1284,16 @@ int parse_arguments(int *argc, const cha
238 + /* if backup_suffix_dels not supplied, default to backup_suffix */
239 + if (!backup_suffix_dels)
240 + backup_suffix_dels = backup_dir_dels ? "" : backup_suffix;
241 + backup_suffix_dels_len = strlen(backup_suffix_dels);
242 + if (strchr(backup_suffix_dels, '/') != NULL) {
243 + snprintf(err_buf, sizeof err_buf,
244 + "--suffix-dels cannot contain slashes: %s\n",
245 + backup_suffix_dels);
249 backup_dir_len = strlcpy(backup_dir_buf, backup_dir, sizeof backup_dir_buf);
250 backup_dir_remainder = sizeof backup_dir_buf - backup_dir_len;
251 @@ -1287,6 +1317,31 @@ int parse_arguments(int *argc, const cha
252 "P *%s", backup_suffix);
253 parse_rule(&filter_list, backup_dir_buf, 0, 0);
255 + /* If backup_dir_dels not supplied default to backup_dir if it has been supplied */
256 + if (backup_dir && !backup_dir_dels) {
257 + backup_dir_dels = backup_dir;
258 + backup_dir_dels_len = backup_dir_len;
259 + backup_dir_dels_remainder = backup_dir_remainder;
260 + strlcpy(backup_dir_dels_buf, backup_dir_buf, sizeof backup_dir_buf);
261 + } else if (backup_dir_dels) {
262 + backup_dir_dels_len = strlcpy(backup_dir_dels_buf, backup_dir_dels, sizeof backup_dir_dels_buf);
263 + backup_dir_dels_remainder = sizeof backup_dir_dels_buf - backup_dir_dels_len;
264 + if (backup_dir_dels_remainder < 32) {
265 + snprintf(err_buf, sizeof err_buf,
266 + "the --backup-dir-dels path is WAY too long.\n");
269 + if (backup_dir_dels_buf[backup_dir_dels_len - 1] != '/') {
270 + backup_dir_dels_buf[backup_dir_dels_len++] = '/';
271 + backup_dir_dels_buf[backup_dir_dels_len] = '\0';
273 + if (verbose > 1 && !am_sender)
274 + rprintf(FINFO, "backup_dir_dels is %s\n", backup_dir_dels_buf);
275 + } else if (!backup_suffix_dels_len && (!am_server || !am_sender)) {
276 + snprintf(err_buf, sizeof err_buf,
277 + "--suffix-dels cannot be a null string without --backup-dir-dels\n");
280 if (make_backups && !backup_dir)
283 @@ -1646,6 +1701,10 @@ void server_options(char **args,int *arg
284 args[ac++] = "--backup-dir";
285 args[ac++] = backup_dir;
287 + if (backup_dir_dels && backup_dir_dels != backup_dir) {
288 + args[ac++] = "--backup-dir-dels";
289 + args[ac++] = backup_dir_dels;
292 /* Only send --suffix if it specifies a non-default value. */
293 if (strcmp(backup_suffix, backup_dir ? "" : BACKUP_SUFFIX) != 0) {
294 @@ -1654,7 +1713,13 @@ void server_options(char **args,int *arg
299 + /* Only send --suffix-dels if it specifies a non-default value. */
300 + if (strcmp(backup_suffix_dels, backup_dir_dels ? "" : BACKUP_SUFFIX) != 0) {
301 + /* We use the following syntax to avoid weirdness with '~'. */
302 + if (asprintf(&arg, "--suffix-dels=%s", backup_suffix_dels) < 0)
308 args[ac++] = "--delete-excluded";