[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sup-talk] Fwd: Automatic labels backup



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
sup-talk@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-talk