まちゅダイアリー

カウンタ復旧

2004-12-15

以前から壊れていた日記のカウンタを復旧させた。 tDiary のカウンタは、データが1週間分バックアップされるようになっているけど、気がついたときには1週間が過ぎていて戻せないようになっていたのだ。

カウンタのデータは PStore というバイナリ形式で保存されているので、手で復旧させるには少し大変だった。 以下、その手順。かなりやっつけなので、真似するときは慎重に。

#!/usr/bin/env ruby
all = yesterday = 0
ARGF.each do |line|
  m = /^(.*) : (\d+),(\d+),(\d+)/.match(line)
  date, today = m[1], m[3].to_i
  all += today
  puts "#{date} : #{all},#{today},#{yesterday}"
  yesterday = today
end
@@ -138,8 +138,6 @@
 =end


-if ["latest", "month", "day"].include?(@mode) and
-  ENV['REQUEST_METHOD'] == 'GET'

 require 'date'
 require 'pstore'
@@ -155,6 +153,10 @@
     @ignore_cookie = false
   end

+  def repair(all, today, yesterday)
+     @all, @today, @yesterday = all, today, yesterday
+  end
+
   def up(now, cache_path, cgi, log)
     if @newestday
       if now == @newestday
#!/usr/bin/env ruby
require 'pstore'
require 'counter'
db = PStore.new('counter.dat')
db.transaction do
  db['countdata'].repair(*ARGV) if ARGV.size == 3
  puts "all: #{db['countdata'].all}"
  puts "today:  #{db['countdata'].today}"
  puts "yesterday: #{db['countdata'].yesterday}"
end

うちの環境はこれで戻っているけど、無茶しているのは間違いない。 ともかく、tDiaryGroph-FlashStyle の表示が綺麗になって(自己)満足。

※ 繰り返しますが、真似するときは慎重にお願いします。壊れても責任はもてません。