Chinaunix首页 | 论坛 | 博客
  • 博客访问: 51645
  • 博文数量: 12
  • 博客积分: 385
  • 博客等级: 一等列兵
  • 技术积分: 115
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-28 11:45
文章分类

全部博文(12)

文章存档

2018年(1)

2017年(1)

2011年(1)

2010年(1)

2009年(6)

2008年(2)

我的朋友

分类:

2009-03-19 16:29:47

 

#!/bin/sh

DateFormat="+%F %T %w"
FilesDir='/data1/db/2.8/'
MountedDir='/mnt/2.8/'

autotobz2() {
## Mount BAK dir.

umount $MountedDir
sqlite3 ${FilesDir}jf28.db "delete from baksize;"

$($execStr)
if test 0 == $?
then
## If mount success.

    sqlite3 ${FilesDir}jf28.db "insert into log values(NULL,'$(date "$DateFormat")','','Success','Mounted $MountedDir');"
## Is files exist?

    ls -l ${MountedDir}etcom_cd_db_*.BAK
    if test 0 == $?
    then
## list file name and size. separator is "|".

        for i in $(ls -l ${MountedDir}etcom_cd_db_*.BAK | sed 's/\// /g' | awk -F " " '{print $11"|"$5}');
        do
## insert file name and size into baksize table.

## for debug echo 'Check: $i1 = '$i

            Filename=$(echo $i | awk -F "|" '{print $1}')
            Filesize=$(echo $i | awk -F "|" '{print $2}')
            sqlite3 ${FilesDir}jf28.db "insert into baksize values('${Filename}','${Filesize}');"
        done
## delete recoder when name and size is same.

        sqlite3 ${FilesDir}jf28.db "delete from baksize where filename in (select k.filename from bz2size z,baksize k where z.filename=k.filename and z.size=k.size);"
## ready Tar, separator is "|".

        for i in $(sqlite3 ${FilesDir}jf28.db "select filename,size from baksize");
        do
## exec Tar operation.

## for debug echo 'Check: $i2 = '$i

            Filename=$(echo $i | awk -F "|" '{print $1}')
            Filesize=$(echo $i | awk -F "|" '{print $2}')
            execStr="tar -jcf $FilesDir$Filename.bz2 $MountedDir$Filename"
            $($execStr)
            if test 0 != $?
            then
                sqlite3 ${FilesDir}jf28.db "insert into log values(NULL,'$(date "$DateFormat")','$execStr','Fail','$(perror $?)');"
            else
                sqlite3 ${FilesDir}jf28.db "delete from bz2size where filename = '$Filename'"
                sqlite3 ${FilesDir}jf28.db "INSERT INTO bz2size VALUES('$Filename','$Filesize');"
                sqlite3 ${FilesDir}jf28.db "insert into log values(NULL,'$(date "$DateFormat")','','Success','$execStr');"
            fi
        done
    else
        sqlite3 ${FilesDir}jf28.db "insert into log values(NULL,'$(date "$DateFormat")','$execStr','Alarm','Not BAK file!');"
    fi
    umount $MountedDir
## If mount fail.

else
    sqlite3 ${FilesDir}jf28.db "insert into log values(NULL,'$(date "$DateFormat")','$execStr','Fail','$(perror $?)');"
fi
}


execStr="mount -t cifs -o username=administrator,password=spat123cd //192.224.2.8/etcomdb_bak1/ $MountedDir"
autotobz2
execStr="mount -t cifs -o username=etcom,password=etcom //192.224.2.8/etcomdb_bak2/ $MountedDir"
autotobz2

阅读(1976) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~