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 | |
6cbbe66d | 22 | @@ -351,6 +352,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"); | |
6cbbe66d | 30 | @@ -570,6 +572,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 }, | |
6cbbe66d | 38 | @@ -1836,7 +1839,8 @@ void server_options(char **args,int *arg |
06dba017 WD |
39 | args[ac++] = "--super"; |
40 | if (size_only) | |
41 | args[ac++] = "--size-only"; | |
42 | - } | |
43 | + } else if (make_source_backups) | |
44 | + args[ac++] = "--source-backup"; | |
45 | ||
46 | if (modify_window_set) { | |
47 | if (asprintf(&arg, "--modify-window=%d", modify_window) < 0) | |
48 | --- old/rsync.yo | |
49 | +++ new/rsync.yo | |
6cbbe66d | 50 | @@ -350,6 +350,7 @@ to the detailed description below for a |
06dba017 WD |
51 | --existing skip creating new files on receiver |
52 | --ignore-existing skip updating files that exist on receiver | |
53 | --remove-source-files sender removes synchronized files (non-dir) | |
54 | + --source-backup ... and backs up those files | |
55 | --del an alias for --delete-during | |
56 | --delete delete extraneous files from dest dirs | |
57 | --delete-before receiver deletes before transfer (default) | |
f362b23e | 58 | @@ -1004,6 +1005,14 @@ dit(bf(--remove-source-files)) This tell |
06dba017 WD |
59 | side the files (meaning non-directories) that are a part of the transfer |
60 | and have been successfully duplicated on the receiving side. | |
61 | ||
62 | +dit(bf(--source-backup)) Makes the sender back up the source files it removes | |
63 | +due to bf(--remove-source-files). This option is independent of | |
64 | +bf(--backup) but uses the same bf(--backup-dir) and bf(--suffix) settings, | |
f362b23e WD |
65 | +if any. With bf(--backup-dir), rsync looks for each file's backup dir relative |
66 | +to the source argument the file came from. Consequently, if the | |
67 | +bf(--backup-dir) path is relative, each source argument gets a separate backup | |
68 | +dir at that path relative to the argument. | |
06dba017 WD |
69 | + |
70 | dit(bf(--delete)) This tells rsync to delete extraneous files from the | |
71 | receiving side (ones that aren't on the sending side), but only for the | |
72 | directories that are being synchronized. You must have asked rsync to | |
73 | --- old/sender.c | |
74 | +++ new/sender.c | |
75 | @@ -39,6 +39,7 @@ extern int protocol_version; | |
76 | extern int remove_source_files; | |
77 | extern int updating_basis_file; | |
78 | extern int make_backups; | |
79 | +extern int make_source_backups; | |
80 | extern int do_progress; | |
81 | extern int inplace; | |
82 | extern int batch_fd; | |
83 | @@ -123,6 +124,7 @@ void successful_send(int ndx) | |
84 | char fname[MAXPATHLEN]; | |
85 | struct file_struct *file; | |
86 | struct file_list *flist; | |
87 | + int result; | |
88 | ||
89 | if (!remove_source_files) | |
90 | return; | |
91 | @@ -139,7 +141,11 @@ void successful_send(int ndx) | |
92 | return; | |
93 | f_name(file, fname); | |
94 | ||
95 | - if (do_unlink(fname) == 0) { | |
96 | + if (make_source_backups) | |
97 | + result = !make_backup(fname); | |
98 | + else | |
99 | + result = do_unlink(fname); | |
100 | + if (result == 0) { | |
101 | if (verbose > 1) | |
102 | rprintf(FINFO, "sender removed %s\n", fname); | |
103 | } else |