事务导出:
import_trans.sh
- TDIR="data/transaction"
- mkdir -pv "$TDIR" >/dev/null 2>&1
- tfile="data/tfile.txt"
- unlink "$tfile" >/dev/null 2>&1
- touch "$tfile" >/dev/null 2>&1
- mysql -uroot -pxxx cmdb -e "select t_transaction.Id, t_transaction.name, descinfo,borntime,count, t_user.user from t_transaction,t_user where t_transaction.valid = 1 and t_transaction.owner = t_user.Id" | awk '{if(NR>1)print$0}' | awk '{if(NF==7)print$0}' | while read ID NAME DESC DATE TIME COUNT OWNER
- do
- NDIR="$TDIR/$ID"
- mkdir -pv "$NDIR" >/dev/null 2>&1
- echo "$NAME" > "$NDIR/name"
- echo "$DESC" > "$NDIR/descinfo"
- echo "$DATE $TIME" > "$NDIR/time"
- echo "$COUNT" > "$NDIR/count"
- echo "$OWNER" > "$NDIR/owner"
- echo "$ID" >>"$tfile"
- done
- cat "$tfile" | while read transid
- do
- NDIR="$TDIR/$transid"
- mkdir -pv "$NDIR" >/dev/null 2>&1
- unlink "$NDIR/polist" >/dev/null 2>&1
- touch "$NDIR/polist"
- if [ "$transid" -lt "1" ]
- then
- echo "error trans_id '$transid' " >> error.log
- continue
- fi
- mysql -uroot -pxxx cmdb -e "select t_trans_pol.f_pol_id, t_trans_pol.idex, t_trans_pol.depd from t_trans_pol where t_trans_pol.f_tran_id = $transid and t_trans_pol.valid = 1 order by t_trans_pol.idex asc" | awk '{if(NR>1)print$0}' | while read pol idx depd
- do
- #echo "$transid-$pol-$depd"
- echo "$pol $idx $depd" >> "$NDIR/polist"
- done
-
- done
- unlink "$tfile" >/dev/null 2>&1
执行完用tree看下结果:
- tree data/transaction/
- data/transaction/
- |-- 46
- | |-- count
- | |-- descinfo
- | |-- name
- | |-- owner
- | |-- polist
- | `-- time
- |-- 47
- | |-- count
- | |-- descinfo
- | |-- name
- | |-- owner
- | |-- polist
- | `-- time
- |-- 48
- | |-- count
- | |-- descinfo
- | |-- name
- | |-- owner
- | |-- polist
- | `-- time
- |-- 49
- | |-- count
- | |-- descinfo
- | |-- name
- | |-- owner
- | |-- polist
- | `-- time
- |-- 50
- | |-- count
- | |-- descinfo
- | |-- name
- | |-- owner
- | |-- polist
- | `-- time
- |-- 51
- | |-- count
- | |-- descinfo
- | |-- name
- | |-- owner
- | |-- polist
- | `-- time
- |-- 52
- | |-- count
- | |-- descinfo
- | |-- name
- | |-- owner
- | |-- polist
- | `-- time
- |-- 53
- | |-- count
- | |-- descinfo
- | |-- name
- | |-- owner
- | |-- polist
- | `-- time
- |-- 54
- | |-- count
- | |-- descinfo
- | |-- name
- | |-- owner
- | |-- polist
- | `-- time
- `-- 55
- |-- count
- |-- descinfo
- |-- name
- |-- owner
- |-- polist
- `-- time
- 10 directories, 60 files