Matt's --source-backup option.
[rsync/rsync-patches.git] / source-backup.diff
CommitLineData
06dba017
WD
1This patch to rsync 2.6.9 adds a --source-backup option that backs up source
2files removed due to --remove-source-files. In my limited testing, it seems
3to work.
4
5To use this patch, run these commands for a successful build:
6
7 patch -p1 <patches/source-backup.diff
8 ./configure (optional if already run)
9 make
10
11-- Matt McCutchen <hashproduct@gmail.com>
12
13--- old/options.c
14+++ new/options.c
15@@ -29,6 +29,7 @@ extern struct filter_list_struct filter_
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
23@@ -350,6 +351,7 @@ void usage(enum logcode F)
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");
31@@ -559,6 +561,7 @@ static struct poptOption long_options[]
32 {"itemize-changes", 'i', POPT_ARG_NONE, 0, 'i', 0, 0 },
33 {"bwlimit", 0, POPT_ARG_INT, &bwlimit, 0, 0, 0 },
34 {"backup", 'b', POPT_ARG_NONE, &make_backups, 0, 0, 0 },
35+ {"source-backup", 0, POPT_ARG_NONE, &make_source_backups, 0, 0, 0},
36 {"backup-dir", 0, POPT_ARG_STRING, &backup_dir, 0, 0, 0 },
37 {"suffix", 0, POPT_ARG_STRING, &backup_suffix, 0, 0, 0 },
38 {"list-only", 0, POPT_ARG_VAL, &list_only, 2, 0, 0 },
39@@ -1820,7 +1823,8 @@ void server_options(char **args,int *arg
40 args[ac++] = "--super";
41 if (size_only)
42 args[ac++] = "--size-only";
43- }
44+ } else if (make_source_backups)
45+ args[ac++] = "--source-backup";
46
47 if (modify_window_set) {
48 if (asprintf(&arg, "--modify-window=%d", modify_window) < 0)
49--- old/rsync.yo
50+++ new/rsync.yo
51@@ -344,6 +344,7 @@ to the detailed description below for a
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)
59@@ -998,6 +999,15 @@ dit(bf(--remove-source-files)) This tell
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,
66+if any. With bf(--backup-dir), each backup file is placed inside the backup
67+dir according to the source file's full path from the working directory
68+(source argument path + file-list path); if you want files placed according
69+to the file-list path, you could either make appropriate symlinks or have the
70+sender "cd" into the source directory so that the source argument is just ".".
71+
72 dit(bf(--delete)) This tells rsync to delete extraneous files from the
73 receiving side (ones that aren't on the sending side), but only for the
74 directories that are being synchronized. You must have asked rsync to
75--- old/sender.c
76+++ new/sender.c
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