[PATCH][RFC] space saving incrementals

jw schultz jw at pegasys.ws
Wed Mar 13 11:22:19 EST 2002


On Mon, Mar 11, 2002 at 12:41:07PM -0600, Dave Dykstra wrote:
> On Fri, Mar 08, 2002 at 03:05:14PM -0800, jw schultz wrote:
> > On Fri, Mar 08, 2002 at 03:45:04PM -0600, Dave Dykstra wrote:
> > > I like link-dest, and the "-" for exclude-from/include-from was already
> > > something I was planning to add one of these days along with the
> > > --files-from option I still plan to write, but --compare-perms confuses
> > > me.  Can you give examples of when you need it?
> > > 
> > > - Dave Dykstra
> > 
> > sequence of commands:
> > 	admin# rsync /project /vault/monday
> > 	admin# chmod 666 /project/somefile
> > 	admin# chown bin /project/someotherfile
> > 	admin# rsync --link-dest=/vault/monday /project /vault/tuesday
> > 
> > Now /vault/monday/somefile has perms of 666 and
> > someotherfile is owned by bin.  I cannot restore the perms
> > from /vault/monday.  That info is lost. /vault/monday no
> > longer is an accurate representative of what existed when it
> > was created.
> > 
> > With --compare-perms somefile and someotherfile will not be
> > linked between monday and tuesday even though the contents
> > haven't changed.
> > 
> > compare-perms only makes sense when you are using link-dest.
> 
> 
> Why not just always do --compare-perms functionality with --link-dest?  I'd
> rather not have more hard-to-explain options if they can be avoided.
> 
> - Dave Dykstra

New patch against current CVS.
Adds --link-dest with compare-perms functionality
and adds the "-" for (ex|in)clude-from.

made with cvs diff -u

-- 
________________________________________________________________
	J.W. Schultz            Pegasystems Technologies
	email address:		jw at pegasys.ws

		Remember Cernan and Schmitt
-------------- next part --------------
Index: exclude.c
===================================================================
RCS file: /cvsroot/rsync/exclude.c,v
retrieving revision 1.42
diff -u -r1.42 exclude.c
--- exclude.c	18 Feb 2002 19:10:28 -0000	1.42
+++ exclude.c	13 Mar 2002 00:25:45 -0000
@@ -219,8 +219,14 @@
 					  int fatal, int include)
 {
 	struct exclude_struct **list=list1;
-	FILE *f = fopen(fname,"r");
+	FILE *f;
 	char line[MAXPATHLEN];
+
+	if (strcmp(fname, "-")) {
+		f = fopen(fname,"r");
+	} else {
+		f = fdopen(0, "r");
+	}
 	if (!f) {
 		if (fatal) {
 			rsyserr(FERROR, errno,
Index: generator.c
===================================================================
RCS file: /cvsroot/rsync/generator.c,v
retrieving revision 1.33
diff -u -r1.33 generator.c
--- generator.c	7 Feb 2002 16:36:12 -0000	1.33
+++ generator.c	13 Mar 2002 00:25:45 -0000
@@ -42,6 +42,7 @@
 extern int always_checksum;
 extern int modify_window;
 extern char *compare_dest;
+extern int link_dest;
 
 
 /* choose whether to skip a particular file */
@@ -51,6 +52,15 @@
 	if (st->st_size != file->length) {
 		return 0;
 	}
+	if (link_dest) {
+		if((st->st_mode & ~_S_IFMT) !=  (file->mode & ~_S_IFMT)) {
+			return 0;
+		}
+		if (st->st_uid != file->uid || st->st_gid != file->gid) {
+			return 0;
+		}
+	}
+
 	
 	/* if always checksum is set then we use the checksum instead 
 	   of the file time to determine whether to sync */
@@ -352,6 +362,17 @@
 			statret = -1;
 		if (statret == -1)
 			errno = saveerrno;
+#if HAVE_LINK
+		else if (link_dest)
+		if (do_link(fnamecmpbuf, fname) != 0) {
+			if (verbose > 0)
+				rprintf(FINFO,"link %s => %s : %s\n",
+					fnamecmpbuf,
+					fname,
+					strerror(errno));
+			fnamecmp = fnamecmpbuf;
+		}
+#endif
 		else
 			fnamecmp = fnamecmpbuf;
 	}
Index: options.c
===================================================================
RCS file: /cvsroot/rsync/options.c,v
retrieving revision 1.80
diff -u -r1.80 options.c
--- options.c	27 Feb 2002 22:49:57 -0000	1.80
+++ options.c	13 Mar 2002 00:25:47 -0000
@@ -105,6 +105,7 @@
 int quiet = 0;
 int always_checksum = 0;
 int list_only = 0;
+int link_dest = 0;
 
 char *batch_prefix = NULL;
 
@@ -224,6 +225,7 @@
   rprintf(F,"     --modify-window=NUM     Timestamp window (seconds) for file match (default=%d)\n",modify_window);
   rprintf(F," -T  --temp-dir=DIR          create temporary files in directory DIR\n");
   rprintf(F,"     --compare-dest=DIR      also compare destination files relative to DIR\n");
+  rprintf(F,"     --link-dest=DIR         create hardlinks to DIR for unchanged files\n");
   rprintf(F," -P                          equivalent to --partial --progress\n");
   rprintf(F," -z, --compress              compress file data\n");
   rprintf(F,"     --exclude=PATTERN       exclude files matching PATTERN\n");
@@ -266,7 +268,8 @@
       OPT_DELETE_AFTER, OPT_EXISTING, OPT_MAX_DELETE, OPT_BACKUP_DIR, 
       OPT_IGNORE_ERRORS, OPT_BWLIMIT, OPT_BLOCKING_IO,
       OPT_NO_BLOCKING_IO, OPT_NO_WHOLE_FILE,
-      OPT_MODIFY_WINDOW, OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_IGNORE_EXISTING};
+      OPT_MODIFY_WINDOW, OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_IGNORE_EXISTING,
+      OPT_LINK_DEST};
 
 static struct poptOption long_options[] = {
   /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
@@ -320,6 +323,7 @@
   {"timeout",          0,  POPT_ARG_INT,    &io_timeout},
   {"temp-dir",        'T', POPT_ARG_STRING, &tmpdir},
   {"compare-dest",     0,  POPT_ARG_STRING, &compare_dest},
+  {"link-dest",        0,  POPT_ARG_STRING, 0,               OPT_LINK_DEST},
   /* TODO: Should this take an optional int giving the compression level? */
   {"compress",        'z', POPT_ARG_NONE,   &do_compression},
   {"daemon",           0,  POPT_ARG_NONE,   &am_daemon},
@@ -535,6 +539,19 @@
 			/* popt stores the filename in batch_prefix for us */
 			read_batch = 1;
 			break;
+		case OPT_LINK_DEST:
+#if HAVE_LINK
+			compare_dest = poptGetOptArg(pc);
+			link_dest = 1;
+			break;
+#else
+			snprintf(err_buf,sizeof(err_buf),
+                                 "hard links are not supported on this %s\n",
+				 am_server ? "server" : "client");
+			rprintf(FERROR,"ERROR: hard links not supported on this platform\n");
+			return 0;
+#endif
+
 
 		default:
                         /* FIXME: If --daemon is specified, then errors for later
Index: rsync.yo
===================================================================
RCS file: /cvsroot/rsync/rsync.yo,v
retrieving revision 1.95
diff -u -r1.95 rsync.yo
--- rsync.yo	6 Feb 2002 21:20:49 -0000	1.95
+++ rsync.yo	13 Mar 2002 00:25:47 -0000
@@ -261,6 +261,7 @@
      --modify-window=NUM     Timestamp window (seconds) for file match (default=0)
  -T  --temp-dir=DIR          create temporary files in directory DIR
      --compare-dest=DIR      also compare destination files relative to DIR
+     --link-dest=DIR         create hardlinks to DIR for unchanged files
  -P                          equivalent to --partial --progress
  -z, --compress              compress file data
      --exclude=PATTERN       exclude files matching PATTERN
@@ -531,6 +532,7 @@
 option, but instead it adds all exclude patterns listed in the file
 FILE to the exclude list.  Blank lines in FILE and lines starting with
 ';' or '#' are ignored.
+If \fIFILE\fP is \fB-\fP the list will be read from standard input.
 
 dit(bf(--include=PATTERN)) This option tells rsync to not exclude the
 specified pattern of filenames. This is useful as it allows you to
@@ -541,6 +543,7 @@
 
 dit(bf(--include-from=FILE)) This specifies a list of include patterns
 from a file.
+If \fIFILE\fP is \fB-\fP the list will be read from standard input.
 
 dit(bf(-C, --cvs-exclude)) This is a useful shorthand for excluding a
 broad range of files that you often don't want to transfer between
@@ -595,6 +598,10 @@
 --partial because partially transferred files will remain in the new
 temporary destination until they have a chance to be completed.  If DIR is
 a relative path, it is relative to the destination directory.
+
+dit(bf(--link-dest=DIR)) This option behaves like \fB--compare-dest\fP but
+also will create hard links from \fIDIR\fP to the destination directory for
+unchanged files\&.
 
 dit(bf(-z, --compress)) With this option, rsync compresses any data from
 the files that it sends to the destination machine.  This


More information about the rsync mailing list