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