crotab+shell实现DB2自动备份表结构和数据(Linux)
2021/11/10 2:09:45
本文主要是介绍crotab+shell实现DB2自动备份表结构和数据(Linux),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
#!/bin/bash -x #设置环境变量为了crontab识别db2look,db2move命令 . /etc/profile . ~/.profile . /home/db2inst1/sqllib/db2profile ymd=$(date +%Y-%m-%d) instanceName="db2inst1"; #/mnt/backup/把window的共享路径绑定到Llinux路径,通过SMP #mount -t cifs basePath="/mnt/backup/${ymd}_auto_backup/${instanceName}"; logPath="${basePath}/log/" logName="${logPath}/backup_${instanceName}_${ymd}.log" #执行成功日志打印路径 function logInfo () { if [ ! -d ${logPath} ] then mkdir -p ${logPath} fi DATE_N=$(date "+%Y-%m-%d %H:%M:%S") USER_N=$(whoami) echo "${DATE_N} ${USER_N} execute $0 [INFO] $@" >>$logName } #执行失败日志打印路径 function log_error () { DATE_N=$(date "+%Y-%m-%d %H:%M:%S") USER_N=$(whoami) echo -e "\033[41;37m ${DATE_N} ${USER_N} execute $0 [ERROR] $@ \033[0m" >>$logName } function fnLog () { if [ $? -eq 0 ] then logInfo "$@ sucessed." echo -e "\033[32m $@ sucessed. \033[0m" else log_error "$@ failed." echo -e "\033[41;37m $@ failed. \033[0m" fi } function daochuSchema() { dbName=$1; schemaPath="${basePath}/${instanceName}_${dbName}_Schema_Bak/" db2 connect to ${dbName}; fnLog "db2 connect to ${dbName};"; if [ ! -d "$schemaPath" ]; then mkdir -p ${schemaPath}; fnLog "mkdir -p ${schemaPath};"; fi cd ${schemaPath}; db2look -d ${dbName} -e -a -l -o "${dbName}_${ymd}".sql; fnLog "db2look -d ${dbName} -e -a -l -o "${dbName}_${ymd}".sql"; } function daochuData() { dbName=$1; dataPath="${basePath}/${instanceName}_${dbName}_Data_Bak" #db2 force applications all; db2 connect to ${dbName}; fnLog "db2 connect to ${dbName};"; if [ ! -d $dataPath ] then mkdir -p ${dataPath}; fnLog "mkdir -p ${dataPath};"; fi cd ${dataPath}; db2move ${dbName} export -aw fnLog "db2move ${dbName} export -aw"; } daochuSchema "SchemaName"; logInfo 'daochuSchema "db2inst1" "SchemaName";' daochuSchema "SchemaName1"; logInfo 'daochuSchema "db2inst1" "SchemaName1";' daochuData "SchemaName"; logInfo 'daochuData "db2inst1" "SchemaName";' daochuData "SchemaName1"; logInfo 'daochuData "db2inst1" "SchemaName1";' exit; #backup.sh修改权限777,配置crontab #* */1 * * db2inst1 "/root/shell/backup.sh"
相关链接:
https://blog.csdn.net/cshongye/article/details/105848597
https://www.cnblogs.com/smitty/p/7356730.html
环境变量配置:
https://blog.csdn.net/u012240363/article/details/88301033
DB2新建实例:
https://blog.csdn.net/super712/article/details/17118525
https://blog.csdn.net/weixin_41282397/article/details/81113014
https://blog.csdn.net/fuwencaho/article/details/30881427
这篇关于crotab+shell实现DB2自动备份表结构和数据(Linux)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-12如何创建可引导的 ESXi USB 安装介质 (macOS, Linux, Windows)
- 2024-11-08linux的 vi编辑器中搜索关键字有哪些常用的命令和技巧?-icode9专业技术文章分享
- 2024-11-08在 Linux 的 vi 或 vim 编辑器中什么命令可以直接跳到文件的结尾?-icode9专业技术文章分享
- 2024-10-22原生鸿蒙操作系统HarmonyOS NEXT(HarmonyOS 5)正式发布
- 2024-10-18操作系统入门教程:新手必看的基本操作指南
- 2024-10-18初学者必看:操作系统入门全攻略
- 2024-10-17操作系统入门教程:轻松掌握操作系统基础知识
- 2024-09-11Linux部署Scrapy学习:入门级指南
- 2024-09-11Linux部署Scrapy:入门级指南
- 2024-08-21【Linux】分区向左扩容的方法