Subject: [sup-talk] Fwd: Automatic labels backup

From: "Edward Z. Yang" <[email-masked]>
Date: Tue, 15 Dec 2009 00:35:42 -0500

Ever had your index corrupted, and your last backup of your labels from
a month ago?  Ever had to go speed through a month's worth of mail?

Well, now, you can /not/ have to do that, with a handy-dandy automated
index dump tool that I've written.  It's at the bottom of the
hooks page here: <http://sup.rubyforge.org/wiki/wiki.pl?Hooks> and I've
reproduced it below for completeness.

This is the first substantial bit of Ruby code I've ever written, so
style nits as well as improvements greatly welcomed; in particular
automatic gzipping of the dumpfiles, and maybe a less braindead backup
rotation technique.

Cheers,
Edward

require 'ftools'

Redwood::reporting_thread("dump") do
    maintain = 7
    wait = 21600
    while true
        say "Rotating dumps"
        filename = File.join(BASE_DIR, "dump")
        maintain.downto(0) do |i|
            rotatename = filename + "." + i.to_s
            if File.exist?(rotatename)
                if i == maintain
                    File.unlink(rotatename)
                else
                    File.move(rotatename, filename + "." + (i+1).to_s)
                end
            end
        end
        say "Dumping labels to .sup/dump.0"
        dumpfile = File.new(filename + ".0", "w")
        Redwood::Index.each_message :load_spam => true, :load_deleted => true, :load_killed => true do |m|
            dumpfile.puts "#{m.id} (#{m.labels.to_a.sort_by { |l| l.to_s } * ' '})"
        end
        dumpfile.close
        say "Done dumping"
        sleep wait
    end
end
_______________________________________________
sup-talk mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-talk

---

From: William Morgan <[email-masked]>
Date: Sat, 19 Dec 2009 11:02:40 -0800

Reformatted excerpts from Edward Z. Yang's message of 2009-12-14:
> Ever had your index corrupted, and your last backup of your labels
> from a month ago?  Ever had to go speed through a month's worth of
> mail?
> 
> index dump tool that I've written.

Thanks, great idea and thank you for adding it to the wiki. I assume you
put this in the startup hooks file?
-- 
William <[email-masked]>
_______________________________________________
sup-talk mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-talk

---

From: "Edward Z. Yang" <[email-masked]>
Date: Sat, 19 Dec 2009 14:13:44 -0500

> put this in the startup hooks file?

Yep!

Edward

---

From: William Baxter <[email-masked]>
Date: Sat, 19 Dec 2009 18:57:24 -0500

> reproduced it below for completeness.

For a few weeks I have used sup to read the same mail on two hosts: an office
desktop and a laptop.  Each host fetches mail from the same IMAP server.  I use
the desktop all day, altering labels frequently, and consequently find reading
from the laptop less useful.  I want to sync labels across the two hosts.

How much additional work does it take to turn an index dump into a sup-to-sup
sync mechanism?  Suppose that on one host you dump the index and send a signed
message.  This reaches the receiving host when you read mail there.  Use it to
update the index, and the receiving host has labels matching those on the
sending host.

Cheers, W.

---

From: William Morgan <[email-masked]>
Date: Mon, 21 Dec 2009 08:35:44 -0800

Reformatted excerpts from William Baxter's message of 2009-12-19:
> How much additional work does it take to turn an index dump into a
> sup-to-sup sync mechanism?  Suppose that on one host you dump the
> index and send a signed message.  This reaches the receiving host when
> you read mail there.  Use it to update the index, and the receiving
> host has labels matching those on the sending host.

It might not be fast or pretty, but should be easy. To sync an index
on computer B based on a dump from computer A, you should be able to
just:

computer B> sup-sync --restore <dumpfile from A>

That should both a) load any new messages from the source, and b) update
them with the labels from the dumpfile.

It's a little silly because you're transmitting the dumpfile for the
entire index back and forth between the two. If it were ordered, you
could just take a portion of it.

I've never tried this, but based on a visual inspection of the code, I
Guarantee It Works (tm).
-- 
William <[email-masked]>
_______________________________________________
sup-talk mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-talk