GBase 8a
备份恢复
文章
Gbase 8a 表级别备份脚本
发表于2024-06-11 17:59:0991次浏览2个评论
提供一个gcrcman进行指定单表或多表进行每周日全备,每日增备,自动删除上一个备份周期内备份的脚本。
可为项目上无虚拟镜像集群,并且共享盘空间有限,只能部分备份重要表做实施备份的策略。
#!/bin/bash
set -e
###########################################
#This script is used to backup gbase database with gcrcman
#Make a full backup once a week
#Do level 1 incremental backup every day
###########################################
source /home/gbase/.gbase_profile
workspace=$(cd `dirname $0`;pwd)
tb_list=$workspace/tb_name.list
backup_base_dir=/gbase_backup
os_gbase_passwd=Dh123456
db_gbase_passwd=gbase20110531
vc_name=vcname000001
db_name=testdb
week=$(date +%u)
d_time=`date "+%F %T %A"`
#####判断备份表列表文件是否存在#####
if [ ! -s ${tb_list} ];then
echo "-------------- tb_name.list is not exist or is empty, please create --------------"
exit
fi
#####判断是否存在备份目录#####
if [ ! -d ${backup_base_dir} ];then
echo "-------------- Please create and mount a backup directory on each data node --------------"
exit
fi
#####判断备份用户是否是gbase#####
if [ `whoami` != "gbase" ];then
echo "-------------- The current user is not gbase, please switch --------------"
exit
fi
#####手动指定库名#####
if [ -n "${1}" ];then
db_name=$1
fi
#####每个周日进行全量备份并删除上一个周期备份#####
if [ $week -eq 7 ];then
while read tb_name
do
backup_dir=${backup_base_dir}/${tb_name}
if [ ! -d ${backup_dir} ];then
mkdir -p ${backup_dir}
fi
backup_log=$backup_dir/${tb_name}.log
gcrcman.py -C -c -D -d ${backup_dir} -P ${os_gbase_passwd} -p ${db_gbase_passwd} -e "backup table ${vc_name}.${db_name}.${tb_name} level 0" >> $backup_log
gcrcman.py -C -c -D -d ${backup_dir} -P ${os_gbase_passwd} -p ${db_gbase_passwd} -e "cleanup" >> ${backup_log}
backup_cycle=$backup_dir/${tb_name}.cycle
gcrcman.py -C -c -D -d ${backup_dir} -P ${os_gbase_passwd} -p ${db_gbase_passwd} -e "show backup" > ${backup_cycle}
#####如果有冗余备份删除冗余备份#####
cycle=`awk 'NR==2 {print $1}' ${backup_cycle}`
cycle_end=`awk 'END {print $1}' ${backup_cycle}`
if [ ${cycle_end} -gt ${cycle} ];then
gcrcman.py -C -c -D -d ${backup_dir} -P ${os_gbase_passwd} -p ${db_gbase_passwd} -e "delete ${cycle}" >> ${backup_log}
fi
echo "---------------------------------------------------- ${d_time} full backup complete ! ----------------------------------------------------" >> ${backup_log}
done < ${tb_list}
else
#####每个非周日进行增量备份#####
while read tb_name
do
backup_dir=${backup_base_dir}/${tb_name}
if [ ! -d ${backup_dir} ];then
mkdir -p ${backup_dir}
fi
backup_log=$backup_dir/${tb_name}.log
gcrcman.py -C -c -D -d ${backup_dir} -P ${os_gbase_passwd} -p ${db_gbase_passwd} -e "backup table ${vc_name}.${db_name}.${tb_name} level 1" >> ${backup_log}
echo "---------------------------------------------------- ${d_time} increment backup complete ! ----------------------------------------------------" >> ${backup_log}
done < ${tb_list}
fi
热门帖子
- 12025-12-01浏览数:182763
- 22023-05-09浏览数:25057
- 42023-09-25浏览数:18525
- 52020-05-11浏览数:17528