bbed批量修改asm的datafile脚本

2021-09-07 18:07:11 浏览数 (1)

**导读**

> 作者:杨漆

> 16年关系型数据库管理,从oracle 9i 、10g、11g、12c到Mysql5.5、5.6、5.7、8.0 到TiDB获得3个OCP、2个OCM;运维路上不平坦,跌过不少坑、熬过许多夜。把工作笔记整理出来分享给大伙儿,希望帮到大家少走弯路、少熬夜。

需要修改的数据文件块特别多时,可以用我写的以下脚本为bbed提供批量修改数据

通过名字过滤出仅含datafile的文件 (此处仅以system文件举例)

ll /data/|grep system|awk '{print $9}' >datafile_name.txt

准备数据块偏移量

cat bbed_repair_data.sh

#!/bin/sh

rm -rf /home/oracle/116.txt

rm -rf /home/oracle/112.txt

rm -rf /home/oracle/140.txt

rm -rf /home/oracle/148.txt

rm -rf /home/oracle/484.txt

rm -rf /home/oracle/488.txt

rm -rf /home/oracle/492.txt

rm -rf /home/oracle/500.txt

rm -rf /home/oracle/504.txt

rm -rf /home/oracle/122.txt

rm -rf /home/oracle/120.txt

rm -rf /home/oracle/order_datafile_name.txt

rm -rf /home/oracle/rm_old_asm_file

cp /home/oracle/datafile_name.txt   /home/oracle/order_datafile_name.txt

cp  /home/oracle/datafile_name.txt /home/oracle/rm_old_asm_file

i=1

cat /home/oracle/datafile_name.txt|while read line

do

sed -i "s/^$line/$i  /data/$line/"  /home/oracle/order_datafile_name.txt

i=$[$i 1]

done

i=1

cat /home/oracle/datafile_name.txt|while read line

do

echo "set dba $i,1">>/home/oracle/112.txt

echo "m /x 88ed offset 112">>/home/oracle/112.txt

echo "Y">>/home/oracle/112.txt

echo "set offset 2">>/home/oracle/112.txt

echo "m /x b03a">>/home/oracle/112.txt

echo "sum apply">>/home/oracle/112.txt

i=$[$i 1]

done

i=1

cat /home/oracle/datafile_name.txt|while read line

do

echo "m /x 01000000 dba $i,1 offset 116">>/home/oracle/116.txt

echo "Y">>/home/oracle/116.txt

echo "sum apply">>/home/oracle/116.txt

i=$[$i 1]

done

i=1

cat /home/oracle/datafile_name.txt|while read line

do

echo "set dba $i,1">>/home/oracle/484.txt

echo "m /x dc2c offset 484">>/home/oracle/484.txt

echo "Y">>/home/oracle/484.txt

echo "set offset 2">>/home/oracle/484.txt

echo "m /x fef4">>/home/oracle/484.txt

echo "sum apply">>/home/oracle/484.txt

i=$[$i 1]

done

i=1

cat /home/oracle/datafile_name.txt|while read line

do

echo "set dba $i,1">>/home/oracle/488.txt

echo "m /x 002e offset 488">>/home/oracle/488.txt

echo "Y">>/home/oracle/488.txt

echo "sum apply">>/home/oracle/488.txt

i=$[$i 1]

done

i=1

cat /home/oracle/datafile_name.txt|while read line

do

echo "m /x 24e54f40 dba $i,1 offset 492">>/home/oracle/492.txt

echo "Y">>/home/oracle/492.txt

echo "sum apply">>/home/oracle/492.txt

i=$[$i 1]

done

i=1

cat /home/oracle/datafile_name.txt|while read line

do

echo "m /x 0f800300 dba $i,1 offset 500">>/home/oracle/500.txt

echo "Y">>/home/oracle/500.txt

echo "sum apply">>/home/oracle/500.txt

i=$[$i 1]

done

i=1

cat /home/oracle/datafile_name.txt|while read line

do

echo "set dba $i,1">>/home/oracle/504.txt

echo "m /x d247 offset 504">>/home/oracle/504.txt

echo "Y">>/home/oracle/504.txt

echo "set offset 2">>/home/oracle/504.txt

echo "m /x 0000">>/home/oracle/504.txt

echo "sum apply">>/home/oracle/504.txt

i=$[$i 1]

done

i=1

cat /home/oracle/datafile_name.txt|while read line

do

echo "m /x 67510400 dba $i,1 offset 148">>/home/oracle/148.txt

echo "Y">>/home/oracle/148.txt

echo "sum apply">>/home/oracle/148.txt

i=$[$i 1]

done

i=1

cat /home/oracle/datafile_name.txt|while read line

do

echo "m /x 68510400 dba $i,1 offset 140">>/home/oracle/140.txt

echo "Y">>/home/oracle/140.txt

echo "sum apply">>/home/oracle/140.txt

i=$[$i 1]

done

i=1

cat /home/oracle/datafile_name.txt|while read line

do

echo "m /x 00000000 dba $i,1 offset 120">>/home/oracle/120.txt

echo "Y">>/home/oracle/120.txt

echo "sum apply">>/home/oracle/120.txt

i=$[$i 1]

done

i=1

cat /home/oracle/datafile_name.txt|while read line

do

echo "m /x 00000000 dba $i,1 offset 122">>/home/oracle/122.txt

echo "Y">>/home/oracle/122.txt

echo "sum apply">>/home/oracle/122.txt

i=$[$i 1]

done

i=1

cat /home/oracle/rm_old_asm_file.txt|while read line

do

sed -i "s/^$line/rm -rf $line/" /home/oracle/rm_old_asm_file.txt

i=$[$i 1]

done

cat  /home/oracle/116.txt > repair.txt

cat  /home/oracle/112.txt >> repair.txt

cat  /home/oracle/140.txt >> repair.txt

cat  /home/oracle/148.txt >> repair.txt

cat  /home/oracle/484.txt >> repair.txt

cat  /home/oracle/488.txt >> repair.txt

cat  /home/oracle/492.txt >> repair.txt

cat  /home/oracle/500.txt >> repair.txt

cat  /home/oracle/504.txt >> repair.txt

cat  /home/oracle/122.txt >> repair.txt

cat  /home/oracle/120.txt >> repair.txt

最后登录bbed, 跑repair.txt里的内容既可完成数据文件块的批量修改

回传ASM前,到grid用户下asmcmd跑rm_old_asm_file.txt内容完成批量删除datafile,之后将bbed修复后的新datafile文件传过来既可

0 人点赞