完了すべき未決 Yum 取引があるかどうかを確認するには?

完了すべき未決 Yum 取引があるかどうかを確認するには?

未解決のYumトランザクションがある場合、Yumは次のコマンドを実行すると次のような内容を出力しますyum update

There are unfinished transactions remaining. You might consider
running yum-complete-transaction first to finish them.

副作用なしに未払い取引があるかどうかを確認するには?(たとえば、解析された出力は、yum updateリポジトリメタデータの更新などの多数の副作用を引き起こします。)


man 8 yum-complete-transaction一致するファイルが存在するかどうかを簡単に確認できることをお勧めします/var/lib/yum/{transaction-all,transaction-done}*(強調表示):

yum-complete-transactionは、システムで不完全または中断されたyumトランザクションを見つけて完了しようとするプログラムです。 yumトランザクションが実行中に中断された場合は、通常/var/lib/yumで見つかるtransaction-all *ファイルとtransaction-done *ファイルを確認します。

未解決のトランザクションが複数見つかった場合は、最新のトランザクションを最初に完了しようとします。複数回実行して未解決のトランザクションをクリーンアップできます。

しかし、これは完全に正確ではないようです。たとえば、これらのファイルが存在するがyum-complete-transaction完了する必要があるトランザクションが残っていないと報告するシステムがあります。

[myhost ~]% ls /var/lib/yum/{transaction-all,transaction-done}*
/var/lib/yum/transaction-all.2016-11-23.07:15.21.disabled
/var/lib/yum/transaction-done.2016-11-23.07:15.21.disabled
[myhost ~]% sudo yum-complete-transaction 
Loaded plugins: product-id, refresh-packagekit, rhnplugin
No unfinished transactions left.

完了していないトランザクションファイルをクリーンアップしようとしましたが、--cleanup-onlyファイルを削除できませんでした。

[myhost ~]% sudo yum-complete-transaction --cleanup-only                   
Loaded plugins: product-id, refresh-packagekit, rhnplugin
No unfinished transactions left.
[myhost ~]% ls /var/lib/yum/{transaction-all,transaction-done}*
/var/lib/yum/transaction-all.2016-11-23.07:15.21.disabled
/var/lib/yum/transaction-done.2016-11-23.07:15.21.disabled

ベストアンサー1

以下は、未解決のトランザクション数を出力するソリューションです。

find /var/lib/yum -maxdepth 1 -type f -name 'transaction-all*' -not -name '*disabled' -printf . | wc -c

yum-complete-transactionsのソースコードによると、yum-utilsすべての/var/lib/yum/transaction-all*ファイルは完了していないトランザクションと見なされます。

def find_unfinished_transactions(yumlibpath='/var/lib/yum'):
    """returns a list of the timestamps from the filenames of the unfinished
       transactions remaining in the yumlibpath specified.
    """
    timestamps = []
    tsallg = '%s/%s' % (yumlibpath, 'transaction-all*')
    #tsdoneg = '%s/%s' % (yumlibpath, 'transaction-done*') # not used remove ?
    tsalls = glob.glob(tsallg)
    #tsdones = glob.glob(tsdoneg) # not used remove ?

    for fn in tsalls:
        trans = os.path.basename(fn)
        timestamp = trans.replace('transaction-all.','')
        timestamps.append(timestamp)

    timestamps.sort()
    return timestamps

...次に終わるファイルを除くdisabled

    times = []
    for thistime in find_unfinished_transactions(self.conf.persistdir):
        if thistime.endswith('disabled'):
            continue
        # XXX maybe a check  here for transactions that are just too old to try and complete?
        times.append(thistime)

    if not times:
        print "No unfinished transactions left."
        sys.exit()

残念ながら、隠されたコードはmain()関数の内部にあるため、yum-complete-transaction.py独立して呼び出すことはできません。このコードがよりモジュール化されている場合は、上記のシェルパイプラインよりも正確に未解決のトランザクションを確認するPythonスクリプトを作成できます。

おすすめ記事