您的位置:首页 > 数据库 > Oracle

Oracle8I数据库冷备份的恢复

2011-12-27 00:07 453 查看
#!/usr/bin/env python
'''This script is used for backup directorys.

you can backup a directory at a time,and also
you can backup multiple directorys at a time.
'''

import tarfile
import os
import sys

#
# the following lines is used to process the directorys
# to be backed up
#

dirs_src = raw_input('Enter directorys that which you want to backup: ')
if dirs_src == '':
sys.exit('you should enter at least one directory')
dirs_src = dirs_src.replace(',', ' ').split(' ')
for judge in dirs_src:
if os.path.isfile(judge):
sys.exit('%s is not a directory' % judge)
dirs = []
for d in dirs_src:
dirs.append(d.rstrip('/'))
#
# the following lines is used to process the directory
# to be placed
#

dest = raw_input('Enter storage path: ')
if dest == '':
sys.exit('you should input a storage path')
if not os.path.exists(dest):
os.makedirs(dest)
if dest[-1] == '/':
pass
else:
dest = dest+'/'
#
# backup section
#

for dir in dirs:
if os.path.exists(dir):
tar_name = dir.lstrip('/').replace('/', '-')
os.chdir(dir)
print dir+' backup is beging...'
files = [n for n in os.listdir(dir)]
tar = tarfile.open('%s%s.tar.gz' % (dest,tar_name),'w:gz')
for name in files:
tar.add(name)
tar.close()
print dir+' backup finished'
else:
print 'There is no directory called '+ dir


本文出自 “永不止步” 博客,请务必保留此出处http://wjcaiyf.blog.51cto.com/7105309/1690833
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: