1 This patches creates two new command line options as follows:
5 The delete-dir and delete-suffix options give the ability to store
6 backup of deleted files on the receiver in different directories
7 or with different suffix than the backup of files that have been
8 changed but that are still on the source drive. Both commands can
11 The default behaviour if one or both of the options are not specified
12 is the previous behaviour, both backups use the same directory or
17 --- orig/backup.c 2005-01-25 12:14:14
18 +++ backup.c 2004-09-22 02:36:06
22 extern int backup_suffix_len;
23 +extern int delete_suffix_len;
24 extern int backup_dir_len;
25 +extern int delete_dir_len;
26 extern unsigned int backup_dir_remainder;
27 +extern unsigned int delete_dir_remainder;
28 extern char backup_dir_buf[MAXPATHLEN];
29 +extern char delete_dir_buf[MAXPATHLEN];
30 extern char *backup_suffix;
31 +extern char *delete_suffix;
32 extern char *backup_dir;
33 +extern char *delete_dir;
36 extern int preserve_devices;
37 @@ -35,6 +41,8 @@ extern int preserve_hard_links;
38 extern int orig_umask;
39 extern int safe_symlinks;
43 /* make a complete pathname for backup file */
44 char *get_backup_name(char *fname)
46 @@ -52,10 +60,27 @@ char *get_backup_name(char *fname)
50 +static char *get_delete_name(char *fname)
53 + if (stringjoin(delete_dir_buf + delete_dir_len, delete_dir_remainder,
54 + fname, delete_suffix, NULL) < delete_dir_remainder)
55 + return delete_dir_buf;
57 + if (stringjoin(delete_dir_buf, MAXPATHLEN,
58 + fname, delete_suffix, NULL) < MAXPATHLEN)
59 + return delete_dir_buf;
62 + rprintf(FERROR, "delete filename too long\n");
66 /* simple backup creates a backup with a suffix in the same directory */
67 static int make_simple_backup(char *fname)
69 - char *fnamebak = get_backup_name(fname);
70 + char *fnamebak = deleting ? get_delete_name(fname)
71 + : get_backup_name(fname);
75 @@ -81,7 +106,8 @@ path
76 static int make_bak_dir(char *fullpath)
79 - char *rel = fullpath + backup_dir_len;
80 + int dir_len = deleting ? delete_dir_len : backup_dir_len;
81 + char *rel = fullpath + dir_len;
82 char *end = rel + strlen(rel);
85 @@ -168,7 +194,8 @@ static int keep_backup(char *fname)
86 if (!(file = make_file(fname, NULL, NO_FILTERS)))
87 return 1; /* the file could have disappeared */
89 - if (!(buf = get_backup_name(fname)))
90 + buf = deleting ? get_delete_name(fname) : get_backup_name(fname);
94 /* Check to see if this is a device file, or link */
95 @@ -259,3 +286,13 @@ int make_backup(char *fname)
96 return keep_backup(fname);
97 return make_simple_backup(fname);
100 +/* backup switch routine called only when backing-up deleted file */
101 +int safe_delete(char *fname)
105 + ret = make_backup(fname);
109 --- orig/flist.c 2005-01-25 12:14:14
110 +++ flist.c 2005-01-24 02:21:33
111 @@ -47,6 +47,8 @@ extern char curr_dir[MAXPATHLEN];
112 extern unsigned int curr_dir_len;
113 extern char *backup_dir;
114 extern char *backup_suffix;
115 +extern char *delete_dir;
116 +extern char *delete_suffix;
117 extern int filesfrom_fd;
119 extern int one_file_system;
120 @@ -61,6 +63,7 @@ extern int relative_paths;
121 extern int implied_dirs;
122 extern int make_backups;
123 extern int backup_suffix_len;
124 +extern int delete_suffix_len;
125 extern int copy_links;
126 extern int copy_unsafe_links;
127 extern int protocol_version;
128 @@ -1659,10 +1662,14 @@ char *f_name(struct file_struct *f)
129 return f_name_to(f, names[n]);
132 +/* Function now checks if file matches backup or delete suffix patterns */
133 static int is_backup_file(char *fn)
135 int k = strlen(fn) - backup_suffix_len;
136 - return k > 0 && strcmp(fn+k, backup_suffix) == 0;
137 + if (k > 0 && strcmp(fn+k, backup_suffix) == 0)
139 + k += backup_suffix_len - delete_suffix_len;
140 + return k > 0 && strcmp(fn+k, delete_suffix) == 0;
143 void delete_in_dir(struct file_list *flist, char *fname)
144 @@ -1716,11 +1723,12 @@ void delete_in_dir(struct file_list *fli
145 || (delete_during && S_ISDIR(mode)
146 && !S_ISDIR(flist->files[j]->mode))) {
147 char *f = f_name(del_flist->files[i]);
148 - if (make_backups && (backup_dir || !is_backup_file(f))
149 + int backup_file = is_backup_file(f);
150 + if (make_backups && (delete_dir || !backup_file)
155 - rprintf(FINFO, "deleting %s\n",
156 + rprintf(FINFO, "safe-deleting %s\n",
160 --- orig/options.c 2005-01-25 12:14:14
161 +++ options.c 2004-11-27 18:37:18
162 @@ -119,10 +119,14 @@ int no_detach = 0;
165 int backup_dir_len = 0;
166 +int delete_dir_len = 0;
167 int backup_suffix_len;
168 +int delete_suffix_len;
169 unsigned int backup_dir_remainder;
170 +unsigned int delete_dir_remainder;
172 char *backup_suffix = NULL;
173 +char *delete_suffix = NULL;
175 char *partial_dir = NULL;
176 char *basis_dir[MAX_BASIS_DIRS+1];
177 @@ -132,7 +136,9 @@ char *log_format = NULL;
178 char *password_file = NULL;
179 char *rsync_path = RSYNC_PATH;
180 char *backup_dir = NULL;
181 +char *delete_dir = NULL;
182 char backup_dir_buf[MAXPATHLEN];
183 +char delete_dir_buf[MAXPATHLEN];
185 int compare_dest = 0;
187 @@ -251,7 +257,9 @@ void usage(enum logcode F)
188 rprintf(F," --no-implied-dirs don't send implied dirs with -R\n");
189 rprintf(F," -b, --backup make backups (see --suffix & --backup-dir)\n");
190 rprintf(F," --backup-dir make backups into this directory\n");
191 + rprintf(F," --delete-dir make backups of deleted files into this directory\n");
192 rprintf(F," --suffix=SUFFIX backup suffix (default %s w/o --backup-dir)\n",BACKUP_SUFFIX);
193 + rprintf(F," --delete-suffix=SUFFIX deleted files suffix (default %s w/o --backup-dir)\n",BACKUP_SUFFIX);
194 rprintf(F," -u, --update update only (don't overwrite newer files)\n");
195 rprintf(F," --inplace update destination files in-place (SEE MAN PAGE)\n");
196 rprintf(F," -d, --dirs transfer directories without recursing\n");
197 @@ -342,6 +350,7 @@ static struct poptOption long_options[]
198 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
199 {"version", 0, POPT_ARG_NONE, 0, OPT_VERSION, 0, 0},
200 {"suffix", 0, POPT_ARG_STRING, &backup_suffix, 0, 0, 0 },
201 + {"delete-suffix", 0, POPT_ARG_STRING, &delete_suffix, 0, 0, 0 },
202 {"rsync-path", 0, POPT_ARG_STRING, &rsync_path, 0, 0, 0 },
203 {"password-file", 0, POPT_ARG_STRING, &password_file, 0, 0, 0 },
204 {"ignore-times", 'I', POPT_ARG_NONE, &ignore_times, 0, 0, 0 },
205 @@ -416,6 +425,7 @@ static struct poptOption long_options[]
206 {"log-format", 0, POPT_ARG_STRING, &log_format, 0, 0, 0 },
207 {"bwlimit", 0, POPT_ARG_INT, &bwlimit, 0, 0, 0 },
208 {"backup-dir", 0, POPT_ARG_STRING, &backup_dir, 0, 0, 0 },
209 + {"delete-dir", 0, POPT_ARG_STRING, &delete_dir, 0, 0, 0 },
210 {"hard-links", 'H', POPT_ARG_NONE, &preserve_hard_links, 0, 0, 0 },
211 {"read-batch", 0, POPT_ARG_STRING, &batch_name, OPT_READ_BATCH, 0, 0 },
212 {"write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_WRITE_BATCH, 0, 0 },
213 @@ -918,6 +928,8 @@ int parse_arguments(int *argc, const cha
214 partial_dir = sanitize_path(NULL, partial_dir, NULL, 0);
216 backup_dir = sanitize_path(NULL, backup_dir, NULL, 0);
218 + delete_dir = sanitize_path(NULL, delete_dir, NULL, 0);
220 files_from = sanitize_path(NULL, files_from, NULL, 0);
222 @@ -944,6 +956,12 @@ int parse_arguments(int *argc, const cha
223 if (check_filter(elp, backup_dir, 1) < 0)
224 goto options_rejected;
226 + /* Clean delete_dir same as for backup_dir */
228 + clean_fname(delete_dir, 1);
229 + if (check_exclude(elp, delete_dir, 1) < 0)
230 + goto options_rejected;
233 if (server_filter_list.head && files_from) {
234 clean_fname(files_from, 1);
235 @@ -964,6 +982,16 @@ int parse_arguments(int *argc, const cha
239 + /* if deleted_suffix not supplied, default to backup_suffix */
240 + if (!delete_suffix)
241 + delete_suffix = delete_dir ? "" : backup_suffix;
242 + delete_suffix_len = strlen(delete_suffix);
243 + if (strchr(delete_suffix, '/') != NULL) {
244 + snprintf(err_buf, sizeof err_buf,
245 + "--delete-suffix cannot contain slashes: %s\n",
250 backup_dir_len = strlcpy(backup_dir_buf, backup_dir, sizeof backup_dir_buf);
251 backup_dir_remainder = sizeof backup_dir_buf - backup_dir_len;
252 @@ -983,6 +1011,31 @@ int parse_arguments(int *argc, const cha
253 "--suffix cannot be a null string without --backup-dir\n");
256 + /* If delete_dir not supplied default to backup_dir if it has been supplied */
257 + if (backup_dir && !delete_dir) {
258 + delete_dir = backup_dir;
259 + delete_dir_len = backup_dir_len;
260 + delete_dir_remainder = backup_dir_remainder;
261 + strlcpy(delete_dir_buf, backup_dir_buf, sizeof backup_dir_buf);
262 + } else if (delete_dir) {
263 + delete_dir_len = strlcpy(delete_dir_buf, delete_dir, sizeof delete_dir_buf);
264 + delete_dir_remainder = sizeof delete_dir_buf - delete_dir_len;
265 + if (delete_dir_remainder < 32) {
266 + snprintf(err_buf, sizeof err_buf,
267 + "the --delete-dir path is WAY too long.\n");
270 + if (delete_dir_buf[delete_dir_len - 1] != '/') {
271 + delete_dir_buf[delete_dir_len++] = '/';
272 + delete_dir_buf[delete_dir_len] = '\0';
274 + if (verbose > 1 && !am_sender)
275 + rprintf(FINFO, "delete_dir is %s\n", delete_dir_buf);
276 + } else if (!delete_suffix_len && (!am_server || !am_sender)) {
277 + snprintf(err_buf, sizeof err_buf,
278 + "--delete-suffix cannot be a null string without --delete-dir\n");
282 if (do_progress && !verbose)
284 @@ -1196,6 +1249,10 @@ void server_options(char **args,int *arg
285 args[ac++] = "--backup-dir";
286 args[ac++] = backup_dir;
289 + args[ac++] = "--delete-dir";
290 + args[ac++] = delete_dir;
293 /* Only send --suffix if it specifies a non-default value. */
294 if (strcmp(backup_suffix, backup_dir ? "" : BACKUP_SUFFIX) != 0) {
295 @@ -1204,7 +1261,13 @@ void server_options(char **args,int *arg
300 + /* Only send --delete-suffix if it specifies a non-default value. */
301 + if (strcmp(delete_suffix, delete_dir ? "" : BACKUP_SUFFIX) != 0) {
302 + /* We use the following syntax to avoid weirdness with '~'. */
303 + if (asprintf(&arg, "--delete-suffix=%s", delete_suffix) < 0)
309 args[ac++] = "--delete-excluded";