脚本内容如下
import datetime
import sys
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