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: e94bad1c156fc3910f24e2b3b71a81b0b0bdeb70
13 diff --git a/options.c b/options.c
16 @@ -32,6 +32,7 @@ extern filter_rule_list filter_list;
17 extern filter_rule_list daemon_filter_list;
20 +int make_source_backups = 0;
23 * If 1, send the whole file as literal data rather than trying to
24 @@ -767,6 +768,7 @@ static struct poptOption long_options[] = {
25 {"bwlimit", 0, POPT_ARG_STRING, &bwlimit_arg, OPT_BWLIMIT, 0, 0 },
26 {"no-bwlimit", 0, POPT_ARG_VAL, &bwlimit, 0, 0, 0 },
27 {"backup", 'b', POPT_ARG_VAL, &make_backups, 1, 0, 0 },
28 + {"source-backup", 0, POPT_ARG_NONE, &make_source_backups, 0, 0, 0},
29 {"no-backup", 0, POPT_ARG_VAL, &make_backups, 0, 0, 0 },
30 {"backup-dir", 0, POPT_ARG_STRING, &backup_dir, 0, 0, 0 },
31 {"suffix", 0, POPT_ARG_STRING, &backup_suffix, 0, 0, 0 },
32 @@ -2768,6 +2770,8 @@ void server_options(char **args, int *argc_p)
36 + if (make_source_backups)
37 + args[ac++] = "--source-backup";
40 if (max_alloc_arg && max_alloc != DEFAULT_MAX_ALLOC) {
41 diff --git a/rsync.1.md b/rsync.1.md
44 @@ -391,6 +391,7 @@ detailed description below for a complete description.
45 --existing skip creating new files on receiver
46 --ignore-existing skip updating files that exist on receiver
47 --remove-source-files sender removes synchronized files (non-dir)
48 +--source-backup ... and backs up those files
49 --del an alias for --delete-during
50 --delete delete extraneous files from dest dirs
51 --delete-before receiver deletes before xfer, not during
52 @@ -1620,6 +1621,16 @@ your home directory (remove the '=' for that).
53 Starting with 3.1.0, rsync will skip the sender-side removal (and output an
54 error) if the file's size or modify time has not stayed unchanged.
58 + Makes the sender back up the source files it removes due to
59 + `--remove-source-files`. This option is independent of `--backup` but uses
60 + the same `--backup-dir` and `--suffix` settings, if any. With
61 + `--backup-dir`, rsync looks for each file's backup dir relative to the
62 + source argument the file came from. Consequently, if the `--backup-dir`
63 + path is relative, each source argument gets a separate backup dir at that
64 + path relative to the argument.
68 This tells rsync to delete extraneous files from the receiving side (ones
69 diff --git a/sender.c b/sender.c
72 @@ -41,6 +41,7 @@ extern int protocol_version;
73 extern int remove_source_files;
74 extern int updating_basis_file;
75 extern int make_backups;
76 +extern int make_source_backups;
78 extern int inplace_partial;
80 @@ -127,6 +128,7 @@ void successful_send(int ndx)
81 struct file_struct *file;
82 struct file_list *flist;
86 if (!remove_source_files)
88 @@ -151,7 +153,11 @@ void successful_send(int ndx)
92 - if (do_unlink(fname) < 0) {
93 + if (make_source_backups)
94 + result = !make_backup(fname, True);
96 + result = do_unlink(fname);