通过python生成导出导入脚本

脚本内容如下

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值