PythonOracle database backup script

Source: Internet
Author: User
Learn Python and change the shell backup script to a Python script trainer. The following is an example of the PythonOracle backup script.

Learn Python and change the shell backup script to a Python script trainer. An example of the Python Oracle backup script is as follows.

Learn Python and change the shell backup script to a Python script trainer. An example of the Python Oracle backup script is as follows.

#! /Usr/bin/env python

#-*-Coding: UTF-8 -*-

Import time

Import OS

# Configuring oracle environment variable parameters

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"

# Print the prompt information.

Exp_node1 = "\ n successfully backed up the file to the directory ...."

Exp_node2 = "backup failed"

Cls_node1 = "the database backup data is cleared successfully. The delete statement is as follows ...."

Cls_node2 = "failed to clear database backup"

# Configure exported database information

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. dmp log = % 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 = "Database Backup execution statement ...."

Print "\ 033 [1; 31; 40 m % s \ 033 [0 m" % exp_note

Print "\ 033 [1; 31; 40 m % s \ 033 [0 m" % exp_command

If OS. system (exp_command) = 0:

Print "\ 033 [1; 32; 40 m % s \ 033 [0 m" % exp_node1

Else:

Print "\ 033 [1; 31; 40 m % s \ 033 [0 m" % 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 "*. log"-exec rm-rf {}\;' % data_path

If OS. system (cls_command1) = 0 and OS. system (cls_command2) = 0:

Print "\ n \ 033 [1; 32; 40 m % s \ 033 [0 m" % cls_node1

Else:

Print "\ n \ 033 [1; 31; 40 m % s \ 033 [0 m" % cls_node2

Print "% s" % cls_command1

Print "% s \ n" % cls_command2

Def main ():

Oracle_exp ()

Backup_clear ()

If _ name _ = "_ main __":

Main ()


Execution result:

Python core programming version 2. (Wesley J. Chun). [Chinese version of hd pdf]

Python development technology details. (Zhou Wei, Zong Jie). [hd PDF scan version + book guide video + code]

Obtain Linux information using a Python script

Build a desktop algorithm transaction research environment using Python in Ubuntu

Python details: click here
Python: click here

,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.