.rsync-/.rsync+ patch and --link-dest example

John Bowman bowman at math.ualberta.ca
Tue Jan 14 16:49:01 EST 2003


This is a patch to add an --rsync-exclude option to rsync-2.5.6cvs.  
File names in .rsync- (or .rsync+) are excluded (or included) from the file
lists associated with the current directory and all of its subdirectories.

This has advantages over --cvs-exclude for backing up large file systems
since the .cvsignore files only apply to the current directory:
unless the .cvsignore restrictions apply to the entire tree they must be
duplicated in each subdirectory. In any case, the --cvs-exclude option
isn't intended for general system backups (for example, unless the default
list is cleared with "!", it automatically excludes *.a libraries).

The .rsync-/.rsync+ mechanism provided by this simple patch provides a more
general solution, since files may be added to or removed from the exclude
list at all levels in the directory hierarchy (similar to apache .htaccess
files).

This patch also adds an example for using --link-dest to the man page: 

"This command creates a linked backup of /home named current on nimbus
relative to a previous backup named previous:

rsync -vax --delete --numeric-ids --link-dest=previous /home nimbus:current"

diff -ru rsync-2.5.6cvs/flist.c rsync-2.5.6cvsJ/flist.c
--- rsync-2.5.6cvs/flist.c	Tue Dec 24 00:42:04 2002
+++ rsync-2.5.6cvsJ/flist.c	Sat Jan 11 03:47:14 2003
@@ -39,6 +39,7 @@
 extern int always_checksum;
 
 extern int cvs_exclude;
+extern int rsync_exclude;
 
 extern int recurse;
 
@@ -64,6 +65,7 @@
 static char topsrcname[MAXPATHLEN];
 
 static struct exclude_struct **local_exclude_list;
+static struct exclude_struct **recur_local_exclude_list;
 
 static struct file_struct null_file;
 
@@ -260,6 +262,9 @@
 	if (check_exclude(fname, local_exclude_list, st)) {
 		return 1;
 	}
+	if (check_exclude(fname, recur_local_exclude_list, st)) {
+		return 1;
+	}
 	return 0;
 }
 
@@ -799,8 +804,11 @@
 	if (S_ISDIR(file->mode) && recursive) {
 		struct exclude_struct **last_exclude_list =
 		    local_exclude_list;
+		struct exclude_struct **recur_last_exclude_list =
+		    recur_local_exclude_list;
 		send_directory(f, flist, f_name(file));
 		local_exclude_list = last_exclude_list;
+		recur_local_exclude_list = recur_last_exclude_list;
 		return;
 	}
 }
@@ -840,6 +848,29 @@
 
 	local_exclude_list = NULL;
 
+	if (rsync_exclude) {
+		if (strlen(fname) + strlen(".rsync-") <= MAXPATHLEN - 1) {
+			strcpy(p, ".rsync-");
+			recur_local_exclude_list =
+			    make_exclude_list(fname, recur_local_exclude_list, 0, 0);
+		} else {
+			io_error = 1;
+			rprintf(FINFO,
+				"cannot cvs-exclude in long-named directory %s\n",
+				fname);
+		}
+		if (strlen(fname) + strlen(".rsync+") <= MAXPATHLEN - 1) {
+			strcpy(p, ".rsync+");
+			recur_local_exclude_list =
+			    make_exclude_list(fname, recur_local_exclude_list, 0, 1);
+		} else {
+			io_error = 1;
+			rprintf(FINFO,
+				"cannot cvs-exclude in long-named directory %s\n",
+				fname);
+		}
+	}
+
 	if (cvs_exclude) {
 		if (strlen(fname) + strlen(".cvsignore") <= MAXPATHLEN - 1) {
 			strcpy(p, ".cvsignore");
diff -ru rsync-2.5.6cvs/options.c rsync-2.5.6cvsJ/options.c
--- rsync-2.5.6cvs/options.c	Tue Jan 14 09:35:25 2003
+++ rsync-2.5.6cvsJ/options.c	Tue Jan 14 09:35:40 2003
@@ -45,6 +45,7 @@
 int preserve_times = 0;
 int update_only = 0;
 int cvs_exclude = 0;
+int rsync_exclude = 0;
 int dry_run=0;
 int local_server=0;
 int ignore_times=0;
@@ -237,6 +238,7 @@
   rprintf(F," -e, --rsh=COMMAND           specify the remote shell\n");
   rprintf(F,"     --rsync-path=PATH       specify path to rsync on the remote machine\n");
   rprintf(F," -C, --cvs-exclude           auto ignore files in the same way CVS does\n");
+  rprintf(F,"     --rsync-exclude         exclude (include) files listed in .rsync- (.rsync+)\n");
   rprintf(F,"     --existing              only update files that already exist\n");
   rprintf(F,"     --ignore-existing       ignore files that already exist on the receiving side\n");
   rprintf(F,"     --delete                delete files that don't exist on the sending side\n");
@@ -324,6 +326,7 @@
   {"dry-run",         'n', POPT_ARG_NONE,   &dry_run , 0, 0, 0 },
   {"sparse",          'S', POPT_ARG_NONE,   &sparse_files , 0, 0, 0 },
   {"cvs-exclude",     'C', POPT_ARG_NONE,   &cvs_exclude , 0, 0, 0 },
+  {"rsync-exclude",   'C', POPT_ARG_NONE,   &rsync_exclude , 0, 0, 0 },
   {"update",          'u', POPT_ARG_NONE,   &update_only , 0, 0, 0 },
   {"links",           'l', POPT_ARG_NONE,   &preserve_links , 0, 0, 0 },
   {"copy-links",      'L', POPT_ARG_NONE,   &copy_links , 0, 0, 0 },
diff -ru rsync-2.5.6cvs/rsync.yo rsync-2.5.6cvsJ/rsync.yo
--- rsync-2.5.6cvs/rsync.yo	Tue Jan 14 09:35:25 2003
+++ rsync-2.5.6cvsJ/rsync.yo	Tue Jan 14 09:35:40 2003
@@ -276,6 +276,11 @@
 
 this is launched from cron every few hours.
 
+This command creates a linked backup of /home named current on nimbus
+relative to a previous backup named previous:
+
+rsync -vax --delete --numeric-ids --link-dest=previous /home nimbus:current
+
 manpagesection(OPTIONS SUMMARY)
 
 Here is a short summary of the options available in rsync. Please refer
@@ -311,6 +316,7 @@
  -e, --rsh=COMMAND           specify the remote shell to use
      --rsync-path=PATH       specify path to rsync on the remote machine
  -C, --cvs-exclude           auto ignore files in the same way CVS does
+     --rsync-exclude         exclude (include) files listed in .rsync- (.rsync+)
      --existing              only update files that already exist
      --ignore-existing       ignore files that already exist on the receiving side
      --delete                delete files that don't exist on the sending side
@@ -654,6 +660,10 @@
 .cvsignore file and matches one of the patterns listed therein.  See
 the bf(cvs(1)) manual for more information.
 
+dit(bf(--rsync-exclude)) File names in .rsync- (or .rsync+) are excluded
+(or included) from the file lists associated with the current directory and
+all of its subdirectories.
+
 dit(bf(--csum-length=LENGTH)) By default the primary checksum used in
 rsync is a very strong 16 byte MD4 checksum. In most cases you will
 find that a truncated version of this checksum is quite efficient, and




More information about the rsync mailing list