脚本内容如下

import datetime
import sys

# print("fromuser="+sys.argv[1])
# print("touser="+sys.argv[2])
# print(datetime.datetime.now().strftime('%Y%m%d'))

# if len(sys.argv)==4:
#     dir = datetime.datetime.now().strftime('%Y%m%d')
# else:
#     dir = sys.argv[4]
dir = datetime.datetime.now().strftime('%Y%m%d')

print("==========exp==========")
with open(sys.argv[3],'r') as f:
    while 1:
        line = f.readline()
        if not line:
            break
        tb=line.strip()
        print(r"exp \'/ as sysdba\' tables=\("+sys.argv[1]+'.'+tb+r"\) file=/backup/expdir/20220322/"+tb+".dmp LOG=/backup/expdir/20220322/"+tb+".log")
print("==========imp==========")
with open(sys.argv[3],'r') as f:
    while 1:
        line = f.readline()
        if not line:
            break
        tb=line.strip()
        print(r"imp \'/ as sysdba\' file=/backup/expdir/"+dir+"/"+tb+".dmp fromuser="+sys.argv[1]+" touser="+sys.argv[2]+" tablespaces="+sys.argv[2]+" LOG=/backup/expdir/"+dir+"/"+tb+".log COMMIT=y BUFFER=104857600")

使用方式

脚本名成为mkies,fromuser表示迁出用户,touser表示迁入用户及表空间,个人环境用户名及表空间名相同,tables.txt表示记录表名的文件
python mkies.py [fromuser] [touser] [tables.txt]
tables.txt格式
table1
table2
table3
table4

迁移脚本示例

PS D:\Practise> python .\mkies.py fromuser touser tables.txt
fromuser=fromuser
touser=touser
20220322
==========exp==========
exp \'/ as sysdba\' tables=\(fromuser.table1\) file=/backup/expdir/20220322/table1.dmp LOG=/backup/expdir/20220322/table1.log
exp \'/ as sysdba\' tables=\(fromuser.table2\) file=/backup/expdir/20220322/table2.dmp LOG=/backup/expdir/20220322/table2.log
exp \'/ as sysdba\' tables=\(fromuser.table3\) file=/backup/expdir/20220322/table3.dmp LOG=/backup/expdir/20220322/table3.log
exp \'/ as sysdba\' tables=\(fromuser.table4\) file=/backup/expdir/20220322/table4.dmp LOG=/backup/expdir/20220322/table4.log
==========imp==========
imp \'/ as sysdba\' file=/backup/expdir/20220322/table1.dmp fromuser=fromuser touser=touser tablespaces=touser LOG=/backup/expdir/20220322/table1.log COMMIT=y BUFFER=104857600
imp \'/ as sysdba\' file=/backup/expdir/20220322/table2.dmp fromuser=fromuser touser=touser tablespaces=touser LOG=/backup/expdir/20220322/table2.log COMMIT=y BUFFER=104857600
imp \'/ as sysdba\' file=/backup/expdir/20220322/table3.dmp fromuser=fromuser touser=touser tablespaces=touser LOG=/backup/expdir/20220322/table3.log COMMIT=y BUFFER=104857600
imp \'/ as sysdba\' file=/backup/expdir/20220322/table4.dmp fromuser=fromuser touser=touser tablespaces=touser LOG=/backup/expdir/20220322/table4.log COMMIT=y BUFFER=104857600
Logo

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。

更多推荐