-
Notifications
You must be signed in to change notification settings - Fork 8
/
source-backup.diff
101 lines (90 loc) · 3.65 KB
/
source-backup.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
This patch adds a --source-backup option that backs up source files
removed due to --remove-source-files.
To use this patch, run these commands for a successful build:
patch -p1 <patches/source-backup.diff
./configure (optional if already run)
make
-- Matt McCutchen <[email protected]>
based-on: 6c8ca91c731b7bf2b081694bda85b7dadc2b7aff
diff --git a/options.c b/options.c
--- a/options.c
+++ b/options.c
@@ -34,6 +34,7 @@ extern filter_rule_list filter_list;
extern filter_rule_list daemon_filter_list;
int make_backups = 0;
+int make_source_backups = 0;
/**
* If 1, send the whole file as literal data rather than trying to
@@ -777,6 +778,7 @@ static struct poptOption long_options[] = {
{"bwlimit", 0, POPT_ARG_STRING, &bwlimit_arg, OPT_BWLIMIT, 0, 0 },
{"no-bwlimit", 0, POPT_ARG_VAL, &bwlimit, 0, 0, 0 },
{"backup", 'b', POPT_ARG_VAL, &make_backups, 1, 0, 0 },
+ {"source-backup", 0, POPT_ARG_NONE, &make_source_backups, 0, 0, 0},
{"no-backup", 0, POPT_ARG_VAL, &make_backups, 0, 0, 0 },
{"backup-dir", 0, POPT_ARG_STRING, &backup_dir, 0, 0, 0 },
{"suffix", 0, POPT_ARG_STRING, &backup_suffix, 0, 0, 0 },
@@ -2840,6 +2842,8 @@ void server_options(char **args, int *argc_p)
} else {
if (skip_compress)
args[ac++] = safe_arg("--skip-compress", skip_compress);
+ if (make_source_backups)
+ args[ac++] = "--source-backup";
}
if (max_alloc_arg && max_alloc != DEFAULT_MAX_ALLOC)
diff --git a/rsync.1.md b/rsync.1.md
--- a/rsync.1.md
+++ b/rsync.1.md
@@ -477,6 +477,7 @@ has its own detailed description later in this manpage.
--existing skip creating new files on receiver
--ignore-existing skip updating files that exist on receiver
--remove-source-files sender removes synchronized files (non-dir)
+--source-backup ... and backs up those files
--del an alias for --delete-during
--delete delete extraneous files from dest dirs
--delete-before receiver deletes before xfer, not during
@@ -1893,6 +1894,17 @@ expand it.
not remove a file the receiver just verified, such as when the user
accidentally makes the source and destination directory the same path.
+0. `--source-backup`
+
+ Makes the sender back up the source files it removes due to
+ [`--remove-source-files`](#opt). This option is independent of
+ [`--backup`](#opt) but uses the same [`--backup-dir`](#opt) and
+ [`--suffix`](#opt) settings, if any. With [`--backup-dir`](#opt), rsync
+ looks for each file's backup dir relative to the source argument the file
+ came from. Consequently, if the [`--backup-dir`](#opt) path is relative,
+ each source argument gets a separate backup dir at that path relative to
+ the argument.
+
0. `--delete`
This tells rsync to delete extraneous files from the receiving side (ones
diff --git a/sender.c b/sender.c
--- a/sender.c
+++ b/sender.c
@@ -44,6 +44,7 @@ extern int protocol_version;
extern int remove_source_files;
extern int updating_basis_file;
extern int make_backups;
+extern int make_source_backups;
extern int inplace;
extern int inplace_partial;
extern int batch_fd;
@@ -131,6 +132,7 @@ void successful_send(int ndx)
struct file_struct *file;
struct file_list *flist;
STRUCT_STAT st;
+ int result;
if (!remove_source_files)
return;
@@ -162,7 +164,11 @@ void successful_send(int ndx)
return;
}
- if (do_unlink(fname) < 0) {
+ if (make_source_backups)
+ result = !make_backup(fname, True);
+ else
+ result = do_unlink(fname);
+ if (result < 0) {
failed_op = "remove";
failed:
if (errno == ENOENT)