From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 10.90.27.4 with SMTP id a4cs221003aga; Mon, 14 Dec 2009 21:38:55 -0800 (PST) Received: by 10.224.80.94 with SMTP id s30mr3604272qak.214.1260855535393; Mon, 14 Dec 2009 21:38:55 -0800 (PST) Return-Path: Received: from rubyforge.org (rubyforge.org [205.234.109.19]) by mx.google.com with ESMTP id 2si13884946qwi.17.2009.12.14.21.38.55; Mon, 14 Dec 2009 21:38:55 -0800 (PST) Received-SPF: pass (google.com: domain of sup-talk-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) client-ip=205.234.109.19; Authentication-Results: mx.google.com; spf=pass (google.com: domain of sup-talk-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) smtp.mail=sup-talk-bounces@rubyforge.org Received: from rubyforge.org (rubyforge.org [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id EBD421858300; Tue, 15 Dec 2009 00:38:48 -0500 (EST) Received: from south-station-annex.mit.edu (SOUTH-STATION-ANNEX.MIT.EDU [18.72.1.2]) by rubyforge.org (Postfix) with ESMTP id 375E718582C1 for ; Tue, 15 Dec 2009 00:35:56 -0500 (EST) Received: from grand-central-station.mit.edu (GRAND-CENTRAL-STATION.MIT.EDU [18.7.21.82]) by south-station-annex.mit.edu (8.13.6/8.9.2) with ESMTP id nBF5ZqIB001205 for ; Tue, 15 Dec 2009 00:35:52 -0500 (EST) Received: from outgoing-legacy.mit.edu (OUTGOING-LEGACY.MIT.EDU [18.7.22.104]) by grand-central-station.mit.edu (8.13.6/8.9.2) with ESMTP id nBF5ZxLr023165 for ; Tue, 15 Dec 2009 00:35:59 -0500 (EST) Received: from localhost (EZYANG.MIT.EDU [18.243.1.50]) ) by outgoing-legacy.mit.edu (8.13.6/8.12.4) with ESMTP id nBF5ZrIj023779 for ; Tue, 15 Dec 2009 00:35:53 -0500 (EST) From: "Edward Z. Yang" To: sup-talk Date: Tue, 15 Dec 2009 00:35:42 -0500 Message-Id: <1260855317-sup-863@ezyang> User-Agent: Sup/git X-Scanned-By: MIMEDefang 2.42 X-Spam-Score: -2.599 X-Spam-Flag: NO Subject: [sup-talk] Fwd: Automatic labels backup X-BeenThere: sup-talk@rubyforge.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: User & developer discussion of Sup List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: sup-talk-bounces@rubyforge.org Errors-To: sup-talk-bounces@rubyforge.org 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: 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