Commit | Line | Data |
---|---|---|
92796ae3 WD |
1 | This patch adds a --source-backup option that backs up source files |
2 | removed due to --remove-source-files. | |
06dba017 WD |
3 | |
4 | To use this patch, run these commands for a successful build: | |
5 | ||
6 | patch -p1 <patches/source-backup.diff | |
7 | ./configure (optional if already run) | |
8 | make | |
9 | ||
10 | -- Matt McCutchen <hashproduct@gmail.com> | |
11 | ||
cc3e685d WD |
12 | diff --git a/options.c b/options.c |
13 | --- a/options.c | |
14 | +++ b/options.c | |
15 | @@ -31,6 +31,7 @@ extern struct filter_list_struct filter_list; | |
06dba017 WD |
16 | extern struct filter_list_struct server_filter_list; |
17 | ||
18 | int make_backups = 0; | |
19 | +int make_source_backups = 0; | |
20 | ||
21 | /** | |
22 | * If 1, send the whole file as literal data rather than trying to | |
cc3e685d | 23 | @@ -361,6 +362,7 @@ void usage(enum logcode F) |
06dba017 WD |
24 | rprintf(F," --existing skip creating new files on receiver\n"); |
25 | rprintf(F," --ignore-existing skip updating files that already exist on receiver\n"); | |
26 | rprintf(F," --remove-source-files sender removes synchronized files (non-dirs)\n"); | |
27 | + rprintf(F," --source-backup ... and backs up those files\n"); | |
28 | rprintf(F," --del an alias for --delete-during\n"); | |
29 | rprintf(F," --delete delete extraneous files from destination dirs\n"); | |
30 | rprintf(F," --delete-before receiver deletes before transfer, not during\n"); | |
cc3e685d | 31 | @@ -588,6 +590,7 @@ static struct poptOption long_options[] = { |
06dba017 | 32 | {"bwlimit", 0, POPT_ARG_INT, &bwlimit, 0, 0, 0 }, |
6cbbe66d WD |
33 | {"no-bwlimit", 0, POPT_ARG_VAL, &bwlimit, 0, 0, 0 }, |
34 | {"backup", 'b', POPT_ARG_VAL, &make_backups, 1, 0, 0 }, | |
06dba017 | 35 | + {"source-backup", 0, POPT_ARG_NONE, &make_source_backups, 0, 0, 0}, |
6cbbe66d | 36 | {"no-backup", 0, POPT_ARG_VAL, &make_backups, 0, 0, 0 }, |
06dba017 WD |
37 | {"backup-dir", 0, POPT_ARG_STRING, &backup_dir, 0, 0, 0 }, |
38 | {"suffix", 0, POPT_ARG_STRING, &backup_suffix, 0, 0, 0 }, | |
cc3e685d | 39 | @@ -1894,6 +1897,8 @@ void server_options(char **args, int *argc_p) |
2ac9130a WD |
40 | goto oom; |
41 | args[ac++] = arg; | |
42 | } | |
43 | + if (make_source_backups) | |
44 | + args[ac++] = "--source-backup"; | |
45 | } | |
06dba017 WD |
46 | |
47 | if (modify_window_set) { | |
cc3e685d WD |
48 | diff --git a/rsync.yo b/rsync.yo |
49 | --- a/rsync.yo | |
50 | +++ b/rsync.yo | |
51 | @@ -361,6 +361,7 @@ to the detailed description below for a complete description. verb( | |
06dba017 WD |
52 | --existing skip creating new files on receiver |
53 | --ignore-existing skip updating files that exist on receiver | |
54 | --remove-source-files sender removes synchronized files (non-dir) | |
55 | + --source-backup ... and backs up those files | |
56 | --del an alias for --delete-during | |
57 | --delete delete extraneous files from dest dirs | |
58 | --delete-before receiver deletes before transfer (default) | |
cc3e685d | 59 | @@ -1085,6 +1086,14 @@ dit(bf(--remove-source-files)) This tells rsync to remove from the sending |
06dba017 WD |
60 | side the files (meaning non-directories) that are a part of the transfer |
61 | and have been successfully duplicated on the receiving side. | |
62 | ||
63 | +dit(bf(--source-backup)) Makes the sender back up the source files it removes | |
64 | +due to bf(--remove-source-files). This option is independent of | |
65 | +bf(--backup) but uses the same bf(--backup-dir) and bf(--suffix) settings, | |
f362b23e WD |
66 | +if any. With bf(--backup-dir), rsync looks for each file's backup dir relative |
67 | +to the source argument the file came from. Consequently, if the | |
68 | +bf(--backup-dir) path is relative, each source argument gets a separate backup | |
69 | +dir at that path relative to the argument. | |
06dba017 WD |
70 | + |
71 | dit(bf(--delete)) This tells rsync to delete extraneous files from the | |
72 | receiving side (ones that aren't on the sending side), but only for the | |
73 | directories that are being synchronized. You must have asked rsync to | |
cc3e685d WD |
74 | diff --git a/sender.c b/sender.c |
75 | --- a/sender.c | |
76 | +++ b/sender.c | |
06dba017 WD |
77 | @@ -39,6 +39,7 @@ extern int protocol_version; |
78 | extern int remove_source_files; | |
79 | extern int updating_basis_file; | |
80 | extern int make_backups; | |
81 | +extern int make_source_backups; | |
82 | extern int do_progress; | |
83 | extern int inplace; | |
84 | extern int batch_fd; | |
85 | @@ -123,6 +124,7 @@ void successful_send(int ndx) | |
86 | char fname[MAXPATHLEN]; | |
87 | struct file_struct *file; | |
88 | struct file_list *flist; | |
89 | + int result; | |
90 | ||
91 | if (!remove_source_files) | |
92 | return; | |
93 | @@ -139,7 +141,11 @@ void successful_send(int ndx) | |
94 | return; | |
95 | f_name(file, fname); | |
96 | ||
97 | - if (do_unlink(fname) == 0) { | |
98 | + if (make_source_backups) | |
99 | + result = !make_backup(fname); | |
100 | + else | |
101 | + result = do_unlink(fname); | |
102 | + if (result == 0) { | |
103 | if (verbose > 1) | |
104 | rprintf(FINFO, "sender removed %s\n", fname); | |
105 | } else |