使用Python备份数据库(Oracle)

Read The Code!


#!/usr/bin/python
#coding=utf-8

import threading
import os
import time

#用户名
user = 'username'
#密码
passwd = 'password'
#备份保存路径
savepath = '/home/oracle/orcl_bak/'
#要备份的表
tables = ' tables=department,employee'
#备份周期
circle = 2.0

#备份命令
global bak_command

bak_command = 'exp '+user+'/'+passwd + ' file=' + savepath

def orclBak():
	now = time.strftime('%Y-%m-%d %H:%M:%S')
	command = bak_command + now + '.dmp' + tables
	print command
	if os.system(command) == 0:
		print '备份成功'
	else:
		print '备份失败'

	global t
	t = threading.Timer(circle, orclBak)
	t.start()

t = threading.Timer(circle, orclBak)
t.start()

  

posted @ 2012-10-17 12:05  梦码人  阅读(3004)  评论(0编辑  收藏  举报