栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

GBase8s核心数据备份

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

GBase8s核心数据备份

GBase8s核心数据备份

​ 做此工具的目的: 有的时候客户没有备份,在数据库出问题的时候修复起来难度和时间成本太高。这个工具就是为了快速处理故障的今早恢复生产而来。

备份项
  1. 保留页

  2. pe

  3. onstat -d

  4. onstat -l

  5. partation页

  6. dbschema

  7. 系统表:sysdatabses,systabnames,systables

备份步骤 备份保留页
oncheck -pr > pr
rootpath=$(onstat -d |awk '$2==1 && $3==1 {print $NF}' )
rootpgsize=$(onstat -d |awk '$2==1 && $4==1 {print $6}')
dd if=$rootpath of=pr0 skip=0 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr1 skip=1 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr2 skip=2 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr3 skip=3 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr4 skip=4 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr5 skip=5 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr6 skip=6 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr7 skip=7 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr8 skip=8 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr9 skip=9 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr10 skip=10 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr11 skip=11 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr12 skip=12 seek=0 bs=$rootpgsize count=1 
备份pe
oncheck -pe > pe
tmpdbs=$(onstat -d |grep "TBA" |awk '{printf("%s|",$NF)}'|sed 's/|$//')
cat pe |grep -E "TBLSpace| /" |grep -vE "$tmpdbs" |grep -v "DBspace Usage"|awk '{
	if ($2~///){path=$2; pgsize=$3*1024}
	if ($1~/TBLSpace/) {print path,pgsize,$2,$3}
}' > TBLSpace.list
cat TBLSpace.list |while read path pgsize begin len
do
	i=$begin
	let end=${begin}+${len}
	name=$(echo $path|awk -F '/' '{print $NF}')
	while [ $i -lt $end ]; do
		dd if=$path of=${name}_${i} skip=$i seek=0 bs=$pgsize count=1 
		let i=$i+1
	done
done

备份onstat -d
onstat -d > on_d
备份onstat -l
onstat -l > on_l
onstat -c > on_c
onstat -g env > on_env
备份sysdatabases
echo "unload to masterDatabas.unl select * from sysdatabases;" |dbaccess sysmaster
echo "unload to masterDblocal.unl select * from sysdbslocale;" |dbaccess sysmaster
备份systabnames
echo "unload to masterTabnames.unl select * from systabnames;" |dbaccess sysmaster
备份库结构dbschema和systables
cat masterDatabas.unl | awk -F | '{print $1}' |while read dbname
do
	dbschema -d $dbname -ss SQL_${dbname}.sql
	echo "unload to Tables_${dbname}.unl select * from systables;" |dbaccess $dbname
done
合并脚本版本 备份核心数据
#!/bin/bash

onmode -c

#保留页
oncheck -pr > pr
rootpath=$(onstat -d |awk '$2==1 && $3==1 {print $NF}' )
rootpgsize=$(onstat -d |awk '$2==1 && $4==1 {print $6}')
dd if=$rootpath of=pr0 skip=0 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr1 skip=1 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr2 skip=2 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr3 skip=3 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr4 skip=4 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr5 skip=5 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr6 skip=6 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr7 skip=7 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr8 skip=8 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr9 skip=9 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr10 skip=10 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr11 skip=11 seek=0 bs=$rootpgsize count=1 
dd if=$rootpath of=pr12 skip=12 seek=0 bs=$rootpgsize count=1 


#pe和patration
oncheck -pe > pe
tmpdbs=$(onstat -d |grep "TBA" |awk '{printf("%s|",$NF)}'|sed 's/|$//')
cat pe |grep -E "TBLSpace| /" |grep -vE "$tmpdbs" |grep -v "DBspace Usage"|awk '{
	if ($2~///){path=$2; pgsize=$3*1024}
	if ($1~/TBLSpace/) {print path,pgsize,$2,$3}
}' > TBLSpace.list
cat TBLSpace.list |while read path pgsize begin len
do
	i=$begin
	let end=${begin}+${len}
	name=$(echo $path|awk -F '/' '{print $NF}')
	while [ $i -lt $end ]; do
		dd if=$path of=${name}_${i} skip=$i seek=0 bs=$pgsize count=1 
		let i=$i+1
	done
done


#环境
onstat -d > on_d
onstat -l > on_l
onstat -c > on_c
onstat -g env > on_env


#全局库
echo "unload to masterDatabas.unl select * from sysdatabases;" |dbaccess sysmaster
echo "unload to masterDblocal.unl select * from sysdbslocale;" |dbaccess sysmaster
echo "unload to masterTabnames.unl select * from systabnames;" |dbaccess sysmaster


#每个库
cat masterDatabas.unl | awk -F | '{print $1}' |while read dbname
do
	dbschema -d $dbname -ss SQL_${dbname}.sql
	echo "unload to Tables_${dbname}.unl select * from systables;" |dbaccess $dbname
done

C语言版本 dumpTBLSall页
#include 
#include 
#include 

char* itoa(int num,char* str,int radix)
{
    char index[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    unsigned unum;
    int i=0,j,k;
 
    
    if(radix==10&&num<0)
    {
        unum=(unsigned)-num;
        str[i++]='-';
    }
    else unum=(unsigned)num;
 
    
    do
    {
        str[i++]=index[unum%(unsigned)radix];
        unum/=radix;
 
    }while(unum);
 
    str[i]='';
 
    
    if(str[0]=='-') k=1;
    else k=0;
 
    char temp;
    for(j=k;j<=(i-1)/2;j++)
    {
        temp=str[j];
        str[j]=str[i-1+k-j];
        str[i-1+k-j]=temp;
    }
 
    return str;
 
}

void writePE(){
        system("oncheck -pe > pe ; sleep 1");
}

void wstrtok(char *str, char s[2], int n, char *list[]){
        int i = 0;
        list[0]=strtok(str,s);
        while(list[i] != NULL){
                list[++i] = strtok(NULL,s);
        }
        for(i=0; i
                if(list[i] != NULL){
                        //printf("%d: %sn",i,list[i]);
                }
        }
}


void dumpAllTBLS(){
        FILE *pe;
        pe = fopen("pe","r");
        if (pe == NULL){
                fputs("打开文件出错!n",stderr);
                exit(1);
        }
        char h[1024];
        char path[200];
        int pgsize;
        int begin ;
        int lens ;
        while (!feof(pe)){
                fgets(h,1025,pe);
                if( ferror(pe) ){
                        break;
                }
                if(strstr(h,"TBLSpace") || strstr(h," /")){
                        if(!strstr(h,"(0x")){
                                if(strstr(h," /")){
                                        char *list[6];
                                        wstrtok(h," ",6,list);
                                        strcpy(path,list[1]);
                                        pgsize = atoi(list[2]);
                                }
                                if(strstr(h,"TBLSpace")){
                                        //printf("%s",h);
                                        char *ltbl[3];
                                        wstrtok(h," ",3,ltbl);
                                        begin = atoi(ltbl[1]);
                                        lens = atoi(ltbl[2]);
                                        printf("#%s %d %d %dn",path,pgsize,begin,lens);
                                        int i = begin;
                                        int end = begin + lens;
                                        char string[1024] ;
                                        strcpy(string,path);
                                        const char sd[2] = "/";
                                        char *name;
                                        char *lastname;
                                        name = strtok(string,sd);
                                        while( name != NULL ){
                                                lastname=name;
                                                name = strtok(NULL,sd);
                                        }
                                        strcat(lastname,"_");
                                        //printf("%s====%s=====%s====n",name,lastname,path);
                                        char strc[200] = {0} ;
                                        char strt[200] = {0} ;
                                        char pgsizes[20] ;
                                        char is[20];
                                        system("mkdir -p pag; mkdir -p txt; ");
                                        //itoa(pgsize,pgsizes,16);
                                        sprintf(pgsizes,"%d",pgsize*1024);
                                        while ( i < end ){
                                                //itoa(i,is,16);
                                                sprintf(is,"%d",i);
                                                strcpy(strc,"dd if=");
                                                strcat(strc,path);
                                                strcat(strc," of=pag/");
                                                strcat(strc,lastname);
                                                strcat(strc,is);
                                                strcat(strc," skip=");
                                                strcat(strc,is);
                                                strcat(strc," bs=");
                                                strcat(strc,pgsizes);
                                                strcat(strc," count=1");
                                                //printf("%sn",strc);
                                                system(strc);

                                                strcpy(strt,"xxd pag/");
                                                strcat(strt,lastname);
                                                strcat(strt,is);
                                                strcat(strt," > txt/");
                                                strcat(strt,lastname);
                                                strcat(strt,is);
                                                strcat(strt,".txt");
                                                //printf("%sn",strt);
                                                system(strt);
                                                i++;
                                        }
                                }
                        }
                }
        }
}

int main(){
        writePE();
        dumpAllTBLS();
        system("tar -zcvf pag.tar.gz pag/");
        system("tar -zcvf txt.tar.gz txt/");
        return 0;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1032294.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号