db2数据库无交互方式db2dart,用于批量脚本
创建文件
vim db2export.py
import os,time
def db2Bak(dbname, dbtsi, start, end):
path = '/tmp/db2data/'
if not os.path.exists( path ):
os.mkdir( path )
#tsi = 2
#osi = 0
for i in range(start,end+1):
print('正在导出ID为%d的表数据'%i)
fname = path + dbname + '_TS%sT%s'%(dbtsi, str(i))
db2cmd = "echo -e '{},{},0,999999\n y\n{}' | db2dart {} /ddel".format(i, dbtsi, fname, dbname)
#print(db2cmd)
os.system(db2cmd)
time.sleep(2)
def main():
dbname = input('请输入数据库名称:')
#dbinst = input('请输入实例名:')
dbtsi = input('请输入表空间ID:')
start = int(input('请输入起始表ID:'))
end = int(input('请输入结尾表ID:'))
db2Bak(dbname, dbtsi, start, end)
if __name__ == '__main__':
main()
执行方法
python3 db2export.py
参考:https://www.ibm.com/support/pages/node/279897