Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

恢复数据的方法讨论 #22

Open
IronBlood opened this issue Sep 18, 2014 · 4 comments
Open

恢复数据的方法讨论 #22

IronBlood opened this issue Sep 18, 2014 · 4 comments
Labels

Comments

@IronBlood
Copy link
Member

目前从老机器上恢复的数据已经拿到。

猜测是文件索引的信息大多数已经损坏,所以绝大部分的目录名、文件名是以 groupnodeobj 加编号来命名的。完整的文件树参见 data.to.be.fixed.tar.gz

粗鲁查看了部分数据内容,文件的分布尚未发现规律。以 unknown 目录为例:

unknown-desc

粗略统计有 1000w 的文本文件需要重命名(并移动到正确的路径)。考虑使用如下的流程来判断并做处理,请评审。

bmyfix

@IronBlood IronBlood added the bug label Sep 18, 2014
@IronBlood
Copy link
Member Author

第一轮恢复的脚本

第一轮仅处理版面文章,精华区文件夹、个人信件、还有一些元数据(例如注册成功、提醒文件等等)暂不做处理。

记录日志的 pglog

#!/usr/bin/env nodejs

var pg = require('pg');
var conString = "postgres://bmy:bmybbs@202.117.3.62/bmy-fix-log";
var client = new pg.Client(conString);

client.connect(function(err, client, done) {
        if(err) {
                return console.error('cannot connet', err);
        }

        client.query('INSERT INTO log(path, status, result) VALUES (\'' + process.argv[2] + '\', \'' + process.argv[3] + '\', \'' + process.argv[4] + '\')', function(err, result) {
                if(err) {
                        return console.error('insert error', err);
                }
//              console.log('insert successfully');
                client.end();
        });
});

处理时间转换的 pts

#!/usr/bin/php
<?php
        echo(strtotime($argv[1]));
?>

执行任务的 bmyfix

#!/bin/bash

BASE=/home/ironblood/boards

if [ -f "$1/count.person" ] ; then
        pglog $1 panding announce
        exit 1
fi

for bmyfile in "$1"/*
do
        if [ -d $bmyfile ] ; then
                bmyfix $bmyfile
        else
                FIRSTLINE=`sed '1q;d' $bmyfile | iconv -f gbk -t utf8`

                if [[ $FIRSTLINE =~ "寄信人" ]] ; then
                        # handle as mail
                        pglog $bmyfile panding PersonalMail
                elif [[ $FIRSTLINE =~ "信区" ]] ; then
                        # handle as board post
                        BOARDNAME=`sed '1q;d' $bmyfile | iconv -f gbk -t utf8 | awk 'BEGIN{FS="信区: "} {print $2}'`
                        TIME=`sed '3q;d' $bmyfile | iconv -f gbk -t utf8 | cut -d"(" -f2 | cut -d")" -f1`
                        TIMESTAMP=`pts "$TIME"`

                        if [ ! -d "$BASE/$BOARDNAME" ] ; then
                                mkdir $BASE/$BOARDNAME -p
                        fi

                        NEWFILENAME=$BASE/$BOARDNAME/M.$TIMESTAMP.A

                        cp $bmyfile $NEWFILENAME

                        pglog $bmyfile successful $NEWFILENAME
                else
                        # handle as normal file
                        pglog $bmyfile panding unknow
                fi
        fi
done

@IronBlood
Copy link
Member Author

第一轮分析结束,现状:

  • 数据库中总计处理条数 2745639 条;
  • 数据库中记录的整理过的版面文章 1360769
  • 位于目标修复路径下的文章数 2105840

分析:

  • 由于第一轮并发过大,某些文件可能处理成功了但是结果没有写入数据库
  • 不确定是否由于资源紧张,部分脚本执行中断,即没有对全部的 8766971 个二级文件/目录都完成了处理
  • 某些版面文件,可能由于版面名称或者时间问题,存放的路径无效

计划补充如下脚本:

  1. 完整扫描 unknown 文件夹,若当前文件没有处理日志,则补充处理
  2. 对路径无效的文件统一再次处理

另外:

  • 考虑用户目录($BBSHOME/home)的修复方案
  • 考虑站内信件的修复方案

@IronBlood
Copy link
Member Author

修复用户文件夹名称的方法

依据目录下的 register/webregister 文件中包含的 userid 字段进行重命名。但是 有关的数据还需要校验,避免长度正确但其实字符值全为 '\0' 的情况。

#!/bin/bash

for i in {A..Z}; do

    FOLDERLIST=`ls $i | grep obj`

    for userhome in $FOLDERLIST
    do
        if [ -f $i/$userhome/register ] ; then
            USERNAME=`sed '2q;d' $i/$userhome/register | cut -d" " -f2`
            if [ ${#USERNAME} -eq 0 ] ; then
                psql -U bmy -h 127.0.0.1 -p 5444 bmy-fix-log -c "INSERT INTO userhomelog(path, status, result) VALUES ('$i/$userhome', 'failed', 'invalid register file');" > /dev/null 2>&1 &
            else
                mv $i/$userhome $i/$USERNAME
                psql -U bmy -h 127.0.0.1 -p 5444 bmy-fix-log -c "INSERT INTO userhomelog(path, status, result) VALUES ('$i/$userhome', 'successful', '$i/$USERNAME');" > /dev/null 2>&1
            fi
        elif [ -f $i/$userhome/webregister ] ; then
            USERNAME=`sed '2q;d' $i/$userhome/webregister | cut -d" " -f2`
            if [ ${#USERNAME} -eq 0 ] ; then
                psql -U bmy -h 127.0.0.1 -p 5444 bmy-fix-log -c "INSERT INTO userhomelog(path, status, result) VALUES ('$i/$userhome', 'failed', 'invalid webregister file');" > /dev/null 2>&1 &
            else
                mv $i/$userhome $i/$USERNAME
                psql -U bmy -h 127.0.0.1 -p 5444 bmy-fix-log -c "INSERT INTO userhomelog(path, status, result) VALUES ('$i/$userhome', 'successful', '$i/$USERNAME');" > /dev/null 2>&1
            fi
        else
            psql -U bmy -h 127.0.0.1 -p 5444 bmy-fix-log -c "INSERT INTO userhomelog(path, status, result) VALUES ('$i/$userhome', 'failed', 'No register files');" > /dev/null 2>&1 &
        fi
    done
done

对于 .PASSWDS 文件中存在,而用户文件夹已经丢失的用户,按照新注册用户补充建立个人文件夹。

此行为会丢失的数据包括:

  • nju09 的自定义样式
  • 签名档
  • 好友名单、黑名单
  • 提醒文件
  • 收藏夹
  • 注册信息
  • 存放已读信息的 brc 文件

@IronBlood
Copy link
Member Author

用户主目录处理数据的结果:

  • 重命名了58791个目录
  • 有46691个目录下 register 或者 webregister 文件未包含 userid 字段
  • 还有4356个目录下不存在 register 或者 webregister 文件

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant