当前位置:网站首页>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;
}
边栏推荐
- 建议收藏丨sql行转列的一千种写法!!
- AI model risk assessment Part 2: core content
- Spark高效数据分析01、idea开发环境搭建
- Use tidymodels to solve the binary logistic model
- Site data collection -scrapy usage notes
- 「PHP基础知识」使用数组保存数据
- 一文搞懂什么是二叉树(二叉树的种类、遍历方式、定义)
- 牛客网刷题
- SkiaSharp 之 WPF 自绘 弹动小球(案例版)
- Detailed arrangement of JVM knowledge points (long text warning)
猜你喜欢

Std:: vector copy, append, nested access

If distributed file storage is realized according to integrated Minio

One click blog building: how to use WordPress plug-in to build a dedicated blog

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

如何使用 grep 跨多行查找模式匹配

美团、饿了么被杭州市监约谈要求落实食品安全管理责任 严禁恶意竞争

QT工程基本构建

8. Interleave - understand ThreadPoolExecutor thread pool from architecture design to practice

LeetCode二叉树系列——144.二叉树的前序遍历

Getting started with pytoch
随机推荐
重磅 | 开放原子校源行活动正式启动
浅谈安科瑞灭弧式智慧用电在养老机构的应用
Spark高效数据分析01、idea开发环境搭建
TCP and UDP
自采集在线电脑壁纸php源码v2.0自适应端
GBase8s核心数据备份
Factoextra: visual PCA of multivariate statistical methods
Niuke net brush questions
sql join中on条件后接and和where
判断两个对象的值是否都相等
std::vector 拷贝、追加、嵌套访问
HMS Core Discovery第16期回顾|与虎墩一起,玩转AI新“声”态
多线程顺序运行的 4 种方法,面试随便问!
Ggdag draw DAG and cause and effect diagram
QWidget、QDialog、QMainWindow 的异同点
开源峰会抢先看 | 7 月 29 日分论坛 & 活动议程速览
Use R-Pack skimr to collect the beautiful display of President measurement
北京大学公开课重磅来袭!欢迎走进「AI for Science」课堂
Open source, compliance escort! 2022 open atom global open source summit open source compliance sub forum is about to open
面试中项目讲解的步骤