gayatrikrishna / memcachedb

Automatically exported from code.google.com/p/memcachedb
Other
0 stars 0 forks source link

MemcacheDB的日志是否可以删除? #13

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
压缩了之后每天也有不少的量,硬盘又小。。
是否可以删除呢?还是可以删除多少天之内的呢?

Original issue reported on code.google.com by Timandes...@gmail.com on 23 Jun 2010 at 6:03

GoogleCodeExporter commented 9 years ago
$BDB_HOME/bin/db_archive -d <home>

$BDB_HOME默认是/usr/local/BerkeleyDB.xx.xx

Original comment by stv...@gmail.com on 23 Jun 2010 at 8:17

GoogleCodeExporter commented 9 years ago
我看到db_archive中-d参数的说明是:
Remove log files that are no longer needed; no filenames are written. This 
automatic log file removal is likely to make catastrophic recovery impossible.

删除不需要的日志,但是无法进行灾难恢复
这是什么意思呢?
那我到底需不需要这些日志呢?

Original comment by Timandes...@gmail.com on 25 Jun 2010 at 3:27

GoogleCodeExporter commented 9 years ago
我模拟了1亿数据,然后就发现了1500多个日志文件,用$BDB_HOME
/bin/db_archive -d 
<home>根本就没用,于是我写了个sh删除脚本,但保留最新的100
个文件,没想到memcachedb启不来了,郁闷

Original comment by achou...@gmail.com on 25 Jun 2010 at 7:44

GoogleCodeExporter commented 9 years ago
db_archive -d 应该是有用的。
如果写删除脚本的话,建议你用db_archive 
-s,他可以分析出当前数据库已经不需要的日志文件的文件名
。
不过我现在自己写的归档脚本默认保留最新的10个文件,目前
没发现起不来的情况。
<?php
class Approach implements IApproach {
    public function run($sPath) {
        $nRemains = 10;
        $aFiles = scandir($sPath, 1);
        $aDestPaths = array();
        $aDestFiles = array();
        $i = 0;
        if($aFiles) foreach($aFiles as $f) {
            $p = $sPath . DIRECTORY_SEPARATOR . $f;
            if(is_dir($p) 
                || strtolower(substr($f, 0, 4)) != "log."
                || strtolower(pathinfo($p, PATHINFO_EXTENSION)) == "gz") {
                continue;
            }

            if($i < $nRemains) {
                $i++;
                continue;
            }

            $aDestPaths[] = $p;
            $aDestFiles[] = $f;
        }

        // pack
        if($aDestFiles) {
            $sDestFiles = implode(" ", $aDestFiles);
            $sArchivePath = $sPath . DIRECTORY_SEPARATOR . strftime("log.%Y%m%d%H%M%S.tar.gz");
            $sCommand = "tar -C $sPath -zcvf $sArchivePath $sDestFiles";
            system($sCommand, $tmp);
        }

        // remove
        if($aDestPaths) foreach($aDestPaths as $p) {
            unlink($p);
        }
    }

    public function getName() {
        return "MemcacheDB日志清理";
    }

    public function getDescription() {
        return "针对MemcacheDB的日志设计的清理及备份方案。";
    }
}
?>

Original comment by Timandes...@gmail.com on 25 Jun 2010 at 7:49

GoogleCodeExporter commented 9 years ago
朋友,加我QQ或gtalk吧,QQ:84608314,gtalk:lth@musicxx.com

Original comment by achou...@gmail.com on 25 Jun 2010 at 9:44