• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Python Oracle数据库备份脚本

mysql 搞代码 4年前 (2022-01-09) 18次浏览 已收录 0个评论

学习Python,将shell备份脚本改成了Python脚本练手,Python Oracle备份脚本一例如下。

学习Python,将shell备份脚本改成了Python脚本练手,Python Oracle备份脚本一例如下。

#!/usr/bin/env python

# -*- coding: utf-8 -*-

import time

import os

#配置oracle环境变量参数

os.environ[“NLS_LANG”] = “Simplified Chinese_china.ZHS16GBK”

os.environ[‘ORACLE_HOME’] = ‘/u01/app/oracle/product/10.2.0/db_1’

os.environ[‘PATH’] = “/u01/app/oracle/product/10.2.0/db_1/bin” + “:” + os.environ[‘PATH’]

os.environ[‘ORACLE_SID’] = “orcl”

os.environ[‘LANG’] = “en_US”

#打印提示信息。

exp_node1 = “\n成功备份文件到目录….”

exp_node2 = “备份失败”

cls_node1 = “数据库备份数据清除成功,删除语句如下….”

cls_node2 = “数据库备份清除失败”

#配置导出的数据库信息

data_path = ‘/tmp/’

db_username = ‘abc’

db_password = ‘abc’

db_name = ‘abc’

“””

print os.getenv(‘NLS_LANG’)

print os.getenv(‘ORACLE_HOME’)

print os.getenv(‘ORACLE_SID’)

“””

def oracle_exp():

exp_command = “exp %s/%s file=%s%s_%s-%s-%s_%s%s%s.dmp log=%s%s_%s-%s-%s_%s%s%s.log” % (db_username,db_password,data_path,db_name,time.strftime(‘%Y’),time.strftime(‘%m’),time.strftime(‘%d’),time.strftime(‘%H’),time.strftime(‘%M’),time.strftime(‘%S’),data_path,db_name,time.strftime(‘%Y’),time.strftime(‘%m’),time.strftime(‘%d’),time.strftime(‘%H’),time.strftime(‘%M’),time.strftime(‘%S’))

exp_note = “数据库备份执行语句….”

print “\033[1;31;40m%s\033[0m” % exp_note

print “\033[1;31;40m%s\033[0m” % exp_command

if os.system(exp_command) == 0:

print “\033[1;32;40m%s\033[0m” % exp_node1

else:

print “\033[1;31;40m%s\033[0m” % exp_node2

def backup_clear():

cls_command1 = ‘/usr/bin/find %s -mtime +1 -name “*.dmp” -exec rm -rf {} \;’ % data_path

cls_command2 = ‘/usr/bin/find %s -mtime +1 -name 本文来源gao@!dai!ma.com搞$$代^@码网*“*.log” -exec rm -rf {} \;’ % data_path

if os.system(cls_command1) == 0 and os.system(cls_command2) == 0:

print “\n\033[1;32;40m%s\033[0m” % cls_node1

else:

print “\n\033[1;31;40m%s\033[0m” % cls_node2

print “%s” % cls_command1

print “%s\n” % cls_command2

def main():

oracle_exp()

backup_clear()

if __name__ == “__main__”:

main()

执行结果:

《Python核心编程 第二版》.(Wesley J. Chun ).[高清PDF中文版]

《Python开发技术详解》.( 周伟,宗杰).[高清PDF扫描版+随书视频+代码]

Python脚本获取Linux系统信息

在Ubuntu下用Python搭建桌面算法交易研究环境

Python 的详细介绍:请点这里
Python 的下载地址:请点这里

本文永久更新链接地址:


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Python Oracle数据库备份脚本

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址