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 2004-09-20 19:50:13
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 @@ -173,7 +199,8 @@ static int keep_backup(char *fname)
86 if (!(file = make_file(fname, NULL, NO_EXCLUDES)))
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);
95 @@ -266,3 +293,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/options.c 2004-09-23 17:42:07
110 +++ options.c 2004-09-22 02:25:03
111 @@ -113,10 +113,14 @@ int no_detach = 0;
114 int backup_dir_len = 0;
115 +int delete_dir_len = 0;
116 int backup_suffix_len;
117 +int delete_suffix_len;
118 unsigned int backup_dir_remainder;
119 +unsigned int delete_dir_remainder;
121 char *backup_suffix = NULL;
122 +char *delete_suffix = NULL;
124 char *partial_dir = NULL;
125 char *compare_dest = NULL;
126 @@ -126,7 +130,9 @@ char *log_format = NULL;
127 char *password_file = NULL;
128 char *rsync_path = RSYNC_PATH;
129 char *backup_dir = NULL;
130 +char *delete_dir = NULL;
131 char backup_dir_buf[MAXPATHLEN];
132 +char delete_dir_buf[MAXPATHLEN];
133 int rsync_port = RSYNC_PORT;
136 @@ -239,7 +245,9 @@ void usage(enum logcode F)
137 rprintf(F," --no-implied-dirs don't send implied dirs with -R\n");
138 rprintf(F," -b, --backup make backups (see --suffix & --backup-dir)\n");
139 rprintf(F," --backup-dir make backups into this directory\n");
140 + rprintf(F," --delete-dir make backups of deleted files into this directory\n");
141 rprintf(F," --suffix=SUFFIX backup suffix (default %s w/o --backup-dir)\n",BACKUP_SUFFIX);
142 + rprintf(F," --delete-suffix=SUFFIX deleted files suffix (default %s w/o --backup-dir)\n",BACKUP_SUFFIX);
143 rprintf(F," -u, --update update only (don't overwrite newer files)\n");
144 rprintf(F," --inplace update destination files inplace (SEE MAN PAGE)\n");
145 rprintf(F," -K, --keep-dirlinks treat symlinked dir on receiver as dir\n");
146 @@ -326,6 +334,7 @@ static struct poptOption long_options[]
147 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
148 {"version", 0, POPT_ARG_NONE, 0, OPT_VERSION, 0, 0},
149 {"suffix", 0, POPT_ARG_STRING, &backup_suffix, 0, 0, 0 },
150 + {"delete-suffix", 0, POPT_ARG_STRING, &delete_suffix, 0, 0, 0 },
151 {"rsync-path", 0, POPT_ARG_STRING, &rsync_path, 0, 0, 0 },
152 {"password-file", 0, POPT_ARG_STRING, &password_file, 0, 0, 0 },
153 {"ignore-times", 'I', POPT_ARG_NONE, &ignore_times, 0, 0, 0 },
154 @@ -396,6 +405,7 @@ static struct poptOption long_options[]
155 {"bwlimit", 0, POPT_ARG_INT, &bwlimit, 0, 0, 0 },
156 {"address", 0, POPT_ARG_STRING, &bind_address, 0, 0, 0 },
157 {"backup-dir", 0, POPT_ARG_STRING, &backup_dir, 0, 0, 0 },
158 + {"delete-dir", 0, POPT_ARG_STRING, &delete_dir, 0, 0, 0 },
159 {"hard-links", 'H', POPT_ARG_NONE, &preserve_hard_links, 0, 0, 0 },
160 {"read-batch", 0, POPT_ARG_STRING, &batch_name, OPT_READ_BATCH, 0, 0 },
161 {"write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_WRITE_BATCH, 0, 0 },
162 @@ -733,6 +743,8 @@ int parse_arguments(int *argc, const cha
163 compare_dest = sanitize_path(NULL, compare_dest, NULL, 0);
165 backup_dir = sanitize_path(NULL, backup_dir, NULL, 0);
167 + delete_dir = sanitize_path(NULL, delete_dir, NULL, 0);
169 files_from = sanitize_path(NULL, files_from, NULL, 0);
171 @@ -758,6 +770,12 @@ int parse_arguments(int *argc, const cha
172 if (check_exclude(elp, backup_dir, 1) < 0)
173 goto options_rejected;
175 + /* Clean delete_dir same as for backup_dir */
177 + clean_fname(delete_dir, 1);
178 + if (check_exclude(elp, delete_dir, 1) < 0)
179 + goto options_rejected;
182 if (server_exclude_list.head && files_from) {
183 clean_fname(files_from, 1);
184 @@ -784,6 +802,16 @@ int parse_arguments(int *argc, const cha
188 + /* if deleted_suffix not supplied, default to backup_suffix */
189 + if (!delete_suffix)
190 + delete_suffix = delete_dir ? "" : backup_suffix;
191 + delete_suffix_len = strlen(delete_suffix);
192 + if (strchr(delete_suffix, '/') != NULL) {
193 + snprintf(err_buf, sizeof err_buf,
194 + "--delete-suffix cannot contain slashes: %s\n",
199 backup_dir_len = strlcpy(backup_dir_buf, backup_dir, sizeof backup_dir_buf);
200 backup_dir_remainder = sizeof backup_dir_buf - backup_dir_len;
201 @@ -803,6 +831,31 @@ int parse_arguments(int *argc, const cha
202 "--suffix cannot be a null string without --backup-dir\n");
205 + /* If delete_dir not supplied default to backup_dir if it has been supplied */
206 + if (backup_dir && !delete_dir) {
207 + delete_dir = backup_dir;
208 + delete_dir_len = backup_dir_len;
209 + delete_dir_remainder = backup_dir_remainder;
210 + strlcpy(delete_dir_buf, backup_dir_buf, sizeof backup_dir_buf);
211 + } else if (delete_dir) {
212 + delete_dir_len = strlcpy(delete_dir_buf, delete_dir, sizeof delete_dir_buf);
213 + delete_dir_remainder = sizeof delete_dir_buf - delete_dir_len;
214 + if (delete_dir_remainder < 32) {
215 + snprintf(err_buf, sizeof err_buf,
216 + "the --delete-dir path is WAY too long.\n");
219 + if (delete_dir_buf[delete_dir_len - 1] != '/') {
220 + delete_dir_buf[delete_dir_len++] = '/';
221 + delete_dir_buf[delete_dir_len] = '\0';
223 + if (verbose > 1 && !am_sender)
224 + rprintf(FINFO, "delete_dir is %s\n", delete_dir_buf);
225 + } else if (!delete_suffix_len && (!am_server || !am_sender)) {
226 + snprintf(err_buf, sizeof err_buf,
227 + "--delete-suffix cannot be a null string without --delete-dir\n");
231 if (do_progress && !verbose)
233 @@ -1009,6 +1062,10 @@ void server_options(char **args,int *arg
234 args[ac++] = "--backup-dir";
235 args[ac++] = backup_dir;
238 + args[ac++] = "--delete-dir";
239 + args[ac++] = delete_dir;
242 /* Only send --suffix if it specifies a non-default value. */
243 if (strcmp(backup_suffix, backup_dir ? "" : BACKUP_SUFFIX) != 0) {
244 @@ -1017,7 +1074,13 @@ void server_options(char **args,int *arg
249 + /* Only send --delete-suffix if it specifies a non-default value. */
250 + if (strcmp(delete_suffix, delete_dir ? "" : BACKUP_SUFFIX) != 0) {
251 + /* We use the following syntax to avoid weirdness with '~'. */
252 + if (asprintf(&arg, "--delete-suffix=%s", delete_suffix) < 0)
258 args[ac++] = "--delete-excluded";
259 --- orig/receiver.c 2004-09-21 09:40:27
260 +++ receiver.c 2004-09-22 02:09:20
261 @@ -42,8 +42,11 @@ extern char *compare_dest;
262 extern int make_backups;
263 extern int do_progress;
264 extern char *backup_dir;
265 +extern char *delete_dir;
266 extern char *backup_suffix;
267 +extern char *delete_suffix;
268 extern int backup_suffix_len;
269 +extern int delete_suffix_len;
270 extern int cleanup_got_literal;
271 extern int module_id;
272 extern int ignore_errors;
273 @@ -77,11 +80,14 @@ static void delete_one(char *fn, int is_
278 +/* Function now checks if file matches backup or delete suffix patterns */
279 static int is_backup_file(char *fn)
281 int k = strlen(fn) - backup_suffix_len;
282 - return k > 0 && strcmp(fn+k, backup_suffix) == 0;
283 + if (k > 0 && strcmp(fn+k, backup_suffix) == 0)
285 + k = strlen(fn) - delete_suffix_len;
286 + return k > 0 && strcmp(fn+k, delete_suffix) == 0;
290 @@ -122,10 +128,11 @@ void delete_files(struct file_list *flis
292 if (flist_find(flist,local_file_list->files[i]) < 0) {
293 char *f = f_name(local_file_list->files[i]);
294 - if (make_backups && (backup_dir || !is_backup_file(f))) {
296 + int backup_file = is_backup_file(f);
297 + if (make_backups && (delete_dir || !backup_file)) {
300 - rprintf(FINFO, "deleting %s\n",
301 + rprintf(FINFO, "safe-deleting %s\n",