cyrreconstruct and resurrected deleted/moved

Steinar Bang sb at dod.no
Tue Feb 14 12:49:46 EST 2006


>>>>> Sebastian Hagedorn <Hagedorn at uni-koeln.de>:

>>>>> Steinar Bang <sb at dod.no>:

>>> So my questions are:
>>> Is there a way short of redoing the Christmas cleanup from an
>>> email client to get back to the state before the massive
>>> delete/move?  Ie. what if I wrote a perl script that unlinked
>>> everything that had more than one hardlink in
>>> /var/spool/cyrus/mail/s/user/myuser/sub/ and then did
>>> cyrreconstruct?

>> That might work, but you're on your own with it ...

Well, now I've tried it, and it (so far) seems to be working.  I wrote
the script /tmp/unlink_moved_imap_articles.pl, which looks like this:

#!/usr/bin/perl
#
# This script will unlink all files in a directory that has both:
#  - A filename matching the pattern [0-9]+\.
#  - More than one hardlink
#
$dirName=".";
opendir(THISDIR,$dirName) || die "Open of $dirName failed!\n";
@files = grep /[0-9]+\./, readdir(THISDIR);
closedir(THISDIR);

$deletecount = 0;
foreach $file (@files) {
    ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($file);
    if ($nlink > 1) {
        print "Removing hardlink for $file...";
        unlink($file);
        print "done!\n";
        $deletecount = $deletecount + 1;
    }
}
print "$deletecount files deleted\n";


Then I did the following as root on the cyrus server machine: 
 /etc/init.d/cyrus21 stop
 cd /var/spool/cyrus/mail/m/user/myusername/subfolder/
 /tmp/unlink_moved_imap_articles.pl
 /bin/su cyrus
 /usr/sbin/cyrreconstruct user.myusername.subfolder
 exit
 /etc/init.d/cyrus21 start

Hopefully I won't be bitten at a later stage...:-)



More information about the Info-cyrus mailing list