Re: [PATCH] Exclude not working?

Peter Baumann <[email protected]> Wed, 26 Jan 2005 17:55:40 +0100
Newsgroups gmane.comp.sysutils.backup.hdup.general
Message-ID <[email protected]>
Hdup2 walks along the directory tree and creates a file named 'filelist'.
There are all files listed which should be included in the backup.
This file is passed to tar which backs up every file in 'filelist'

That's where the problem begins :-)

Because every file is explicitly named in filelist, the
--one-file-system option doesn't work. hdup2 has to exclude the
mountpoints, so they never appear in 'filelist'


Following patch solved my problem, but it's not 100% correct compaired
with how tar is  handling --one-file-system.

Example:


peter@xp/mnt$ dir
total 48
drwxr-xr-x  12 root root  4096 2004-11-26 02:28 ./
drwxr-xr-x  25 root root  4096 2005-01-22 13:36 ../
drwxrwxr-x   8 root root  4096 2004-07-18 17:12 hde7/
drwx------   2 root root  4096 2004-11-26 01:31 test/


peter@xp~$ df|grep hde7
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/hde7             46125316  42449976   1332264  97% /mnt/hde7

># Notice: /mnt/test is a normal directory and not a mountpoint

peter@xp~$ tar -cvf /tmp/test.tar --one-file-system /mnt

peter@xp~$ tar -tvzf /tmp/test.tar
drwxr-xr-x root/root         0 2004-11-26 02:28:23 mnt/
drwx------ root/root         0 2005-01-26 17:17:31 mnt/test/
-rw------- root/root         0 2005-01-26 17:17:29 mnt/test/file1
-rw------- root/root         0 2005-01-26 17:17:31 mnt/test/file2



The same procedure with hdup (with the patch below apllied) will
backup these files:

peter@xp~$ tar -tvzf /tmp/storage/xp/2005-01-26/xp.2005-01-26.monthly.tar.gz
-rw------- root/root         0 2005-01-26 17:17:29 mnt/test/file1
-rw------- root/root         0 2005-01-26 17:17:31 mnt/test/file2


Conclusion:

The directory witch is a mountpoint (/mnt/hde7) is not included but
IMHO this is ok.

Greetings,
  Peter Baumann


Here is the patch:


--- walker.c.orig	2005-01-26 17:01:55.000000000 +0100
+++ walker.c	2005-01-26 17:02:04.000000000 +0100
@@ -150,7 +150,8 @@ walk_dir(char *path, FILE *fp, phost_t h
 	char *newpath;
 	struct dirent *d;
 	struct stat s;
-	
+	dev_t current_dev;
+
 	unsigned int dsize = 50;
 	unsigned int dirs = 1;
 	unsigned int files = 1;
@@ -170,6 +171,14 @@ walk_dir(char *path, FILE *fp, phost_t h
 		WARN("%s: %s", "Cannot enter the directory", path);
 		return 0;
 	}
+	
+	/* get device */
+	if (stat(path, &s) != 0) {
+		WARN("%s: %s","Cannot determine holding device of the directory:", path);
+		return 0;
+	}
+
+	current_dev = s.st_dev;
 
 	while((d = readdir(dir))) {
 		if (hdup_sig)
@@ -230,6 +239,11 @@ walk_dir(char *path, FILE *fp, phost_t h
 			
 
 		} else if(S_ISDIR(s.st_mode)) {
+			/* one filesystem */
+			if (host->onefile && (s.st_dev != current_dev)) {
+				continue;
+			}
+
 			/* dir excludes */
 			if (reg_do_match(dexclude, newpath)) {
 				/* a match don't add this dir - but
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iD8DBQFB98uM1DA7u6p6WVURAh6tAJ9A6CcCd2Qz7Bi6YXpR7hyoQsRYmACeMNLr
dUBa9yhsJVFGTQH+NO5sxc0=
=IXY+
-----END PGP SIGNATURE-----