#!/usr/bin/perl -w # # This script is invoked to generate the list of rsync exclusion patterns # (mostly anchored absolute directory names). Used by the # rsync-backup script. # use strict; my @exclude_dirs; my $t; my $h; my $type; my $mountpoint; my @roots; push(@roots, '/'); push(@roots, glob("/r+b/*/f8/root/")); push(@roots, glob("/r+b/*/f10/root/")); # There are some directories we just never want to backup (especially # the backup directory itself). Include unused boot partitions in this list. foreach $_ (qw(/backup/ /zooty/temp/ /zooty/tmp/ /zooty/build/ /r+b/amd64/f9/ /r+b/i386/f9/ /secure/)) { push(@exclude_dirs, $_); } # Some of the directories we don't want to backup are the same on every # version of linux on the system, so iterate through all the root partitions # building the names. foreach $_ (@roots, '/var/named/chroot/') { foreach $t (qw(tmp/ var/tmp/ var/cache/ var/log/ var/lock/ usr/tmp/ proc/ dev/ sys/ media/ mnt/ misc/ selinux/ net/ )) { push(@exclude_dirs, "${_}$t"); } } # I happen to know that all my local hard disks are ext3. Anything else that # is mounted, I don't want in the backup, so exclue it. open($h, '-|', "mount") || die "Cannot run mount : $!\n"; while (<$h>) { chomp; if (/^\S+\s+on\s+(\S+)\s+type\s+(\S+)\s+/) { $mountpoint = $1; $type = $2; if ($type ne "ext3") { push(@exclude_dirs, "$mountpoint/"); } } } close($h) || die "Error running mount command : $!\n"; # Some of the entries I have in the list now are subdirectories of other # entries. Squish out the longer (or duplicate) names implicitly excluded # via a parent directory exclusion. my @newlist; my $lastdir; foreach $_ (sort(@exclude_dirs)) { if (! (defined($lastdir) && (length($lastdir) <= length($_)) && ($lastdir eq substr($_,0,length($lastdir))))) { push(@newlist, $_); $lastdir = $_; } } @exclude_dirs = @newlist; # Some un-interesting directories are scattered around in places like # different user home directories. Exclude these directories without any # anchor. # Used to have .Trash in this list, but that's the name of the imap # trashcan in dovecot's ~/Maildir directory, and things go all squirrely # if it doesn't get restored in a backup (as I discovered :-). # # push(@exclude_dirs, ".Trash/"); push(@exclude_dirs, ".ccache/"); push(@exclude_dirs, ".glameswap/"); push(@exclude_dirs, ".thumbnails/"); push(@exclude_dirs, "Cache/"); push(@exclude_dirs, "TextCache/"); push(@exclude_dirs, "cache/"); # Now print the list in rsync --exclude-from file format foreach $_ (@exclude_dirs) { print "- $_\n"; }