当前位置:网站首页>Gbase8s core data backup
Gbase8s core data backup
2022-07-29 10:59:00 【wangwei830】
GBase8s Core data backup
The purpose of this tool : Sometimes customers don't back up , It is too difficult and time-consuming to repair the database when it goes wrong . This tool is to quickly deal with the fault and resume production this morning .
Backup items
Reserved page
pe
onstat -d
onstat -l
partation page
dbschema
The system tables :sysdatabses,systabnames,systables
Backup steps
Backup retention page
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
Backup 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
Backup onstat -d
onstat -d > on_d
Backup onstat -l
onstat -l > on_l
onstat -c > on_c
onstat -g env > on_env
Backup sysdatabases
echo "unload to masterDatabas.unl select * from sysdatabases;" |dbaccess sysmaster
echo "unload to masterDblocal.unl select * from sysdbslocale;" |dbaccess sysmaster
Backup systabnames
echo "unload to masterTabnames.unl select * from systabnames;" |dbaccess sysmaster
Backup library structure dbschema and 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
Merge script versions Back up core data
#!/bin/bash
onmode -c
# Reserved page
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 and 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
# Environmental Science
onstat -d > on_d
onstat -l > on_l
onstat -c > on_c
onstat -g env > on_env
# Global Library
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
# Each library
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 Language version dumpTBLSall page
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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]='\0';
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<n; i++){
if(list[i] != NULL){
//printf("%d: %s\n",i,list[i]);
}
}
}
void dumpAllTBLS(){
FILE *pe;
pe = fopen("pe","r");
if (pe == NULL){
fputs(" Error opening file !\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 %d\n",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("%s\n",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("%s\n",strt);
system(strt);
i++;
}
}
}
}
}
}
int main(){
writePE();
dumpAllTBLS();
system("tar -zcvf pag.tar.gz pag/");
system("tar -zcvf txt.tar.gz txt/");
return 0;
}
边栏推荐
- 开源峰会抢先看 | 7 月 29 日分论坛 & 活动议程速览
- 2.安装MySQL
- 美团、饿了么被杭州市监约谈要求落实食品安全管理责任 严禁恶意竞争
- 如何使用 grep 跨多行查找模式匹配
- Watch the open source summit first | quick view of the sub Forum & Activity agenda on July 29
- 阿里架构师耗时一年整理的《Lucene高级文档》,吃透你也是大厂员工!
- WPF 截图控件之绘制方框与椭圆(四) 「仿微信」
- 聊聊性能测试环境搭建
- Talk about the establishment of performance testing environment
- 【图像检测】基于灰度图像的积累加权边缘检测方法研究附matlab代码
猜你喜欢

Discussion on the application of arcing smart electricity in elderly care institutions

Zhou Hongyi: 360 is the largest secure big data company in the world

TCP and UDP

报表控件FastReport与StimulSoft功能对比

The 2022 open atom global open source summit opened in Beijing

PHP basics uses arrays to save data

如何在匹配行之前使用 grep 显示文件名和行号

Peking University open classes are coming! Welcome to the "AI for science" class

阿里架构师耗时一年整理的《Lucene高级文档》,吃透你也是大厂员工!

Exclusive interview | Cheng Li, chief technology officer of Alibaba: cloud + open source together form a credible foundation for the digital world
随机推荐
Hugo NexT V4 介绍
LeetCode_ 1049_ Weight of the last stone II
R language Monte Carlo method and average method are used to calculate the definite integral. Considering the random point casting method, the confidence is 0.05, and the requirement is ϵ= 0.01, numbe
Spark高效数据分析01、idea开发环境搭建
js两个数组对象进行合并去重
If distributed file storage is realized according to integrated Minio
Peking University open classes are coming! Welcome to the "AI for science" class
阿里架构师耗时一年整理的《Lucene高级文档》,吃透你也是大厂员工!
DOD and Dor, two artifacts to reduce "cognitive bias"
【图像检测】基于灰度图像的积累加权边缘检测方法研究附matlab代码
Basic construction of QT project
带你浅聊一下PHP搭建的电商商城系统
️ 炒 股 实 战丨原 地 起 飞 ️
判断两个对象的值是否都相等
Sunwenlong, Secretary General of the open atom open source foundation, worked together to expand open source
2022最新 wifi大师小程序独立版3.0.8
基本.分块
ECCV 2022 | ssp: a new idea of small sample tasks with self-supporting matching
Alibaba P8 broke out this interview guide for big factories. After reading it, the salary soared by 30K!
Watch the open source summit first | quick view of the sub Forum & Activity agenda on July 29