1 This patch adds a --source-backup option that backs up source files
2 removed due to --remove-source-files.
4 To use this patch, run these commands for a successful build:
6 patch -p1 <patches/source-backup.diff
7 ./configure (optional if already run)
10 -- Matt McCutchen <hashproduct@gmail.com>
12 based-on: 40afd365cc8ca968fd16e161d24df5b8a8a520cc
13 diff --git a/options.c b/options.c
16 @@ -33,6 +33,7 @@ extern struct filter_list_struct filter_list;
17 extern struct filter_list_struct daemon_filter_list;
20 +int make_source_backups = 0;
23 * If 1, send the whole file as literal data rather than trying to
24 @@ -366,6 +367,7 @@ void usage(enum logcode F)
25 rprintf(F," --existing skip creating new files on receiver\n");
26 rprintf(F," --ignore-existing skip updating files that already exist on receiver\n");
27 rprintf(F," --remove-source-files sender removes synchronized files (non-dirs)\n");
28 + rprintf(F," --source-backup ... and backs up those files\n");
29 rprintf(F," --del an alias for --delete-during\n");
30 rprintf(F," --delete delete extraneous files from destination dirs\n");
31 rprintf(F," --delete-before receiver deletes before transfer, not during\n");
32 @@ -606,6 +608,7 @@ static struct poptOption long_options[] = {
33 {"bwlimit", 0, POPT_ARG_INT, &bwlimit, 0, 0, 0 },
34 {"no-bwlimit", 0, POPT_ARG_VAL, &bwlimit, 0, 0, 0 },
35 {"backup", 'b', POPT_ARG_VAL, &make_backups, 1, 0, 0 },
36 + {"source-backup", 0, POPT_ARG_NONE, &make_source_backups, 0, 0, 0},
37 {"no-backup", 0, POPT_ARG_VAL, &make_backups, 0, 0, 0 },
38 {"backup-dir", 0, POPT_ARG_STRING, &backup_dir, 0, 0, 0 },
39 {"suffix", 0, POPT_ARG_STRING, &backup_suffix, 0, 0, 0 },
40 @@ -1978,6 +1981,8 @@ void server_options(char **args, int *argc_p)
44 + if (make_source_backups)
45 + args[ac++] = "--source-backup";
48 if (modify_window_set) {
49 diff --git a/rsync.yo b/rsync.yo
52 @@ -378,6 +378,7 @@ to the detailed description below for a complete description. verb(
53 --existing skip creating new files on receiver
54 --ignore-existing skip updating files that exist on receiver
55 --remove-source-files sender removes synchronized files (non-dir)
56 + --source-backup ... and backs up those files
57 --del an alias for --delete-during
58 --delete delete extraneous files from dest dirs
59 --delete-before receiver deletes before xfer, not during
60 @@ -1203,6 +1204,14 @@ transferring files that are not yet finished (e.g. name the file "foo.new" when
61 it is written, rename it to "foo" when it is done, and then use the option
62 bf(--exclude='*.new') for the rsync transfer).
64 +dit(bf(--source-backup)) Makes the sender back up the source files it removes
65 +due to bf(--remove-source-files). This option is independent of
66 +bf(--backup) but uses the same bf(--backup-dir) and bf(--suffix) settings,
67 +if any. With bf(--backup-dir), rsync looks for each file's backup dir relative
68 +to the source argument the file came from. Consequently, if the
69 +bf(--backup-dir) path is relative, each source argument gets a separate backup
70 +dir at that path relative to the argument.
72 dit(bf(--delete)) This tells rsync to delete extraneous files from the
73 receiving side (ones that aren't on the sending side), but only for the
74 directories that are being synchronized. You must have asked rsync to
75 diff --git a/sender.c b/sender.c
78 @@ -38,6 +38,7 @@ extern int protocol_version;
79 extern int remove_source_files;
80 extern int updating_basis_file;
81 extern int make_backups;
82 +extern int make_source_backups;
83 extern int do_progress;
86 @@ -122,6 +123,7 @@ void successful_send(int ndx)
87 char fname[MAXPATHLEN];
88 struct file_struct *file;
89 struct file_list *flist;
92 if (!remove_source_files)
94 @@ -132,7 +134,11 @@ void successful_send(int ndx)
98 - if (do_unlink(fname) == 0) {
99 + if (make_source_backups)
100 + result = !make_backup(fname);
102 + result = do_unlink(fname);
105 rprintf(FINFO, "sender removed %s\n", fname);