DNF でインストールやアップデートした履歴を確認してみた

ターミナルのログをロストしてしまっても絶望しなくて済む
2023.07.31

このアップデートでどのパッケージがアップデートされたのか知りたい

こんにちは、のんピ(@non____97)です。

皆さんはAmazon Linux 2023やRed Hat Enterprise Linux (以降RHEL)にて、dnf upgradeした時にアップデートされたパッケージを後で見返したいと思ったことはありますか? 私はあります。

そんな時はdnf historyで確認します。

試してみたので紹介します。

いきなりまとめ

  • dnf historyでdnfのトランザクションを確認可能
  • トランザクションのロールバック、再実行が可能
  • トランザクションからどのパッケージがインストール/アップデート/削除されたのか確認することが可能

やってみた

dnf upgrade の実行履歴を確認する

検証用のEC2インスタンスとしてRHEL 9.2のEC2インスタンスを用意しました。

AMIの名前とus-east-1上のIDは以下の通りです。

  • RHEL-9.2.0_HVM-20230503-x86_64-41-Hourly2-GP2
  • ami-026ebd4cfe2c043b2

dnf upgradeします。

$ sudo dnf upgrade
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Last metadata expiration check: 0:03:24 ago on Mon 31 Jul 2023 08:17:26 AM UTC.
Dependencies resolved.
=====================================================================================================================================================
 Package                                     Architecture     Version                                    Repository                             Size
=====================================================================================================================================================
Installing:
 kernel                                      x86_64           5.14.0-284.18.1.el9_2                      rhel-9-baseos-rhui-rpms               3.4 M
 kernel-core                                 x86_64           5.14.0-284.18.1.el9_2                      rhel-9-baseos-rhui-rpms                17 M
 kernel-modules                              x86_64           5.14.0-284.18.1.el9_2                      rhel-9-baseos-rhui-rpms                37 M
 kernel-modules-core                         x86_64           5.14.0-284.18.1.el9_2                      rhel-9-baseos-rhui-rpms                36 M
Upgrading:
 NetworkManager                              x86_64           1:1.42.2-3.el9_2                           rhel-9-baseos-rhui-rpms               2.2 M
 NetworkManager-cloud-setup                  x86_64           1:1.42.2-3.el9_2                           rhel-9-appstream-rhui-rpms             73 k
 NetworkManager-libnm                        x86_64           1:1.42.2-3.el9_2                           rhel-9-baseos-rhui-rpms               1.8 M
 NetworkManager-team                         x86_64           1:1.42.2-3.el9_2                           rhel-9-baseos-rhui-rpms                39 k
 NetworkManager-tui                          x86_64           1:1.42.2-3.el9_2                           rhel-9-baseos-rhui-rpms               243 k
 c-ares                                      x86_64           1.17.1-5.el9_2.1                           rhel-9-baseos-rhui-rpms               106 k
 insights-client                             noarch           3.1.7-12.1.el9_2                           rhel-9-appstream-rhui-rpms            1.2 M
 iputils                                     x86_64           20210202-8.el9_1.1                         rhel-9-baseos-rhui-rpms               178 k
 kernel-tools                                x86_64           5.14.0-284.18.1.el9_2                      rhel-9-baseos-rhui-rpms               3.7 M
 kernel-tools-libs                           x86_64           5.14.0-284.18.1.el9_2                      rhel-9-baseos-rhui-rpms               3.4 M
 kexec-tools                                 x86_64           2.0.25-13.el9_2.1                          rhel-9-baseos-rhui-rpms               499 k
 krb5-libs                                   x86_64           1.20.1-9.el9_2                             rhel-9-baseos-rhui-rpms               731 k
 less                                        x86_64           590-2.el9_2                                rhel-9-baseos-rhui-rpms               166 k
 microcode_ctl                               noarch           4:20220809-2.20230214.1.el9_2              rhel-9-baseos-rhui-rpms               7.5 M
 openssl                                     x86_64           1:3.0.7-16.el9_2                           rhel-9-baseos-rhui-rpms               1.2 M
 openssl-libs                                x86_64           1:3.0.7-16.el9_2                           rhel-9-baseos-rhui-rpms               2.2 M
 python-unversioned-command                  noarch           3.9.16-1.el9_2.1                           rhel-9-appstream-rhui-rpms             11 k
 python3                                     x86_64           3.9.16-1.el9_2.1                           rhel-9-baseos-rhui-rpms                30 k
 python3-libs                                x86_64           3.9.16-1.el9_2.1                           rhel-9-baseos-rhui-rpms               7.8 M
 python3-perf                                x86_64           5.14.0-284.18.1.el9_2                      rhel-9-baseos-rhui-rpms               3.6 M
 redhat-cloud-client-configuration           noarch           1-10.el9_0                                 rhel-9-appstream-rhui-rpms             20 k
 rh-amazon-rhui-client                       noarch           4.0.9-1.el9                                rhui-client-config-server-9            38 k
 selinux-policy                              noarch           38.1.11-2.el9_2.3                          rhel-9-baseos-rhui-rpms                56 k
 selinux-policy-targeted                     noarch           38.1.11-2.el9_2.3                          rhel-9-baseos-rhui-rpms               6.8 M
 systemd                                     x86_64           252-14.el9_2.1                             rhel-9-baseos-rhui-rpms               4.1 M
 systemd-libs                                x86_64           252-14.el9_2.1                             rhel-9-baseos-rhui-rpms               652 k
 systemd-pam                                 x86_64           252-14.el9_2.1                             rhel-9-baseos-rhui-rpms               257 k
 systemd-rpm-macros                          noarch           252-14.el9_2.1                             rhel-9-baseos-rhui-rpms                45 k
 systemd-udev                                x86_64           252-14.el9_2.1                             rhel-9-baseos-rhui-rpms               1.9 M

Transaction Summary
=====================================================================================================================================================
Install   4 Packages
Upgrade  29 Packages

Total download size: 144 M
Is this ok [y/N]: y
Downloading Packages:
(1/33): kernel-5.14.0-284.18.1.el9_2.x86_64.rpm                                                                       30 MB/s | 3.4 MB     00:00
(2/33): kernel-core-5.14.0-284.18.1.el9_2.x86_64.rpm                                                                  35 MB/s |  17 MB     00:00
(3/33): redhat-cloud-client-configuration-1-10.el9_0.noarch.rpm                                                      1.0 MB/s |  20 kB     00:00
(4/33): python-unversioned-command-3.9.16-1.el9_2.1.noarch.rpm                                                       1.1 MB/s |  11 kB     00:00
.
.
(中略)
.
.
Installed products updated.

Upgraded:
  NetworkManager-1:1.42.2-3.el9_2.x86_64                                    NetworkManager-cloud-setup-1:1.42.2-3.el9_2.x86_64
  NetworkManager-libnm-1:1.42.2-3.el9_2.x86_64                              NetworkManager-team-1:1.42.2-3.el9_2.x86_64
  NetworkManager-tui-1:1.42.2-3.el9_2.x86_64                                c-ares-1.17.1-5.el9_2.1.x86_64
  insights-client-3.1.7-12.1.el9_2.noarch                                   iputils-20210202-8.el9_1.1.x86_64
  kernel-tools-5.14.0-284.18.1.el9_2.x86_64                                 kernel-tools-libs-5.14.0-284.18.1.el9_2.x86_64
  kexec-tools-2.0.25-13.el9_2.1.x86_64                                      krb5-libs-1.20.1-9.el9_2.x86_64
  less-590-2.el9_2.x86_64                                                   microcode_ctl-4:20220809-2.20230214.1.el9_2.noarch
  openssl-1:3.0.7-16.el9_2.x86_64                                           openssl-libs-1:3.0.7-16.el9_2.x86_64
  python-unversioned-command-3.9.16-1.el9_2.1.noarch                        python3-3.9.16-1.el9_2.1.x86_64
  python3-libs-3.9.16-1.el9_2.1.x86_64                                      python3-perf-5.14.0-284.18.1.el9_2.x86_64
  redhat-cloud-client-configuration-1-10.el9_0.noarch                       rh-amazon-rhui-client-4.0.9-1.el9.noarch
  selinux-policy-38.1.11-2.el9_2.3.noarch                                   selinux-policy-targeted-38.1.11-2.el9_2.3.noarch
  systemd-252-14.el9_2.1.x86_64                                             systemd-libs-252-14.el9_2.1.x86_64
  systemd-pam-252-14.el9_2.1.x86_64                                         systemd-rpm-macros-252-14.el9_2.1.noarch
  systemd-udev-252-14.el9_2.1.x86_64
Installed:
  kernel-5.14.0-284.18.1.el9_2.x86_64                  kernel-core-5.14.0-284.18.1.el9_2.x86_64     kernel-modules-5.14.0-284.18.1.el9_2.x86_64
  kernel-modules-core-5.14.0-284.18.1.el9_2.x86_64

Complete!

33個のパッケージがインストールもしくはアップデートされました。

dnf historyで実行結果を確認します。

$ dnf history
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

ID     | Command line                                                                                   | Date and time    | Action(s)      | Altered
-----------------------------------------------------------------------------------------------------------------------------------------------------
     2 | upgrade                                                                                        | 2023-07-31 08:21 | I, U           |   33 E<
     1 | install -y https://s3.us-east-1.amazonaws.com/amazon-ssm-us-east-1/latest/linux_amd64/amazon-s | 2023-07-31 08:17 | Install        |    1 >E

IDの2が先ほどdnf upgradeした時の実行結果です。実行日時やインストールなのかアップデートなのか、影響あったパッケージの数が表示されています。

Action(s)及び、Alteredの値はdnfのマニュアルに記載がありました。

The "Action(s)" column lists each type of action taken in the transaction. The possible values are:

• Install (I): a new package was installed on the system

• Downgrade (D): an older version of a package replaced the previously-installed version

• Obsolete (O): an obsolete package was replaced by a new package

• Upgrade (U): a newer version of the package replaced the previously-installed version

• Remove (E): a package was removed from the system

• Reinstall (R): a package was reinstalled with the same version

• Reason change (C): a package was kept in the system but its reason for being installed changed

The "Altered" column lists the number of actions taken in each transaction, possibly followed by one or two the following symbols:

• >: The RPM database was changed, outside DNF, after the transaction

• &lt; : The RPM database was changed, outside DNF, before the transaction

• *: The transaction aborted before completion

• #: The transaction completed, but with a non-zero status

• E: The transaction completed successfully, but had warning/error output

詳細を確認します。

$ dnf history info 2
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Transaction ID : 2
Begin time     : Mon 31 Jul 2023 08:21:04 AM UTC
Begin rpmdb    : 3fa0058f1ea6ee5978f6b365a1d47dd2a7d1cf6e0be8d1541b26feeccdce417e
End time       : Mon 31 Jul 2023 08:24:48 AM UTC (224 seconds)
End rpmdb      : 7dad51b1cbad6c54f36cb461b7e40302f5a1c428a8be7151e22eedddb68e4482
User           : System <unset>
Return-Code    : Success
Releasever     : 9
Command Line   : upgrade
Comment        :
Packages Altered:
    Install  kernel-modules-5.14.0-284.18.1.el9_2.x86_64         @rhel-9-baseos-rhui-rpms
    Install  kernel-core-5.14.0-284.18.1.el9_2.x86_64            @rhel-9-baseos-rhui-rpms
    Install  kernel-5.14.0-284.18.1.el9_2.x86_64                 @rhel-9-baseos-rhui-rpms
    Install  kernel-modules-core-5.14.0-284.18.1.el9_2.x86_64    @rhel-9-baseos-rhui-rpms
    Upgrade  redhat-cloud-client-configuration-1-10.el9_0.noarch @rhel-9-appstream-rhui-rpms
    Upgraded redhat-cloud-client-configuration-1-10.el9.noarch   @@System
    Upgrade  python-unversioned-command-3.9.16-1.el9_2.1.noarch  @rhel-9-appstream-rhui-rpms
    Upgraded python-unversioned-command-3.9.16-1.el9.noarch      @@System
    Upgrade  insights-client-3.1.7-12.1.el9_2.noarch             @rhel-9-appstream-rhui-rpms
    Upgraded insights-client-3.1.7-12.el9.noarch                 @@System
    Upgrade  NetworkManager-cloud-setup-1:1.42.2-3.el9_2.x86_64  @rhel-9-appstream-rhui-rpms
    Upgraded NetworkManager-cloud-setup-1:1.42.2-1.el9.x86_64    @@System
    Upgrade  iputils-20210202-8.el9_1.1.x86_64                   @rhel-9-baseos-rhui-rpms
    Upgraded iputils-20210202-8.el9.x86_64                       @@System
    Upgrade  c-ares-1.17.1-5.el9_2.1.x86_64                      @rhel-9-baseos-rhui-rpms
    Upgraded c-ares-1.17.1-5.el9.x86_64                          @@System
    Upgrade  python3-3.9.16-1.el9_2.1.x86_64                     @rhel-9-baseos-rhui-rpms
    Upgraded python3-3.9.16-1.el9.x86_64                         @@System
    Upgrade  python3-libs-3.9.16-1.el9_2.1.x86_64                @rhel-9-baseos-rhui-rpms
    Upgraded python3-libs-3.9.16-1.el9.x86_64                    @@System
    Upgrade  microcode_ctl-4:20220809-2.20230214.1.el9_2.noarch  @rhel-9-baseos-rhui-rpms
    Upgraded microcode_ctl-4:20220809-2.el9.noarch               @@System
    Upgrade  openssl-1:3.0.7-16.el9_2.x86_64                     @rhel-9-baseos-rhui-rpms
    Upgraded openssl-1:3.0.7-6.el9_2.x86_64                      @@System
    Upgrade  selinux-policy-targeted-38.1.11-2.el9_2.3.noarch    @rhel-9-baseos-rhui-rpms
    Upgraded selinux-policy-targeted-38.1.11-2.el9_2.2.noarch    @@System
    Upgrade  python3-perf-5.14.0-284.18.1.el9_2.x86_64           @rhel-9-baseos-rhui-rpms
    Upgraded python3-perf-5.14.0-284.11.1.el9_2.x86_64           @@System
    Upgrade  NetworkManager-1:1.42.2-3.el9_2.x86_64              @rhel-9-baseos-rhui-rpms
    Upgraded NetworkManager-1:1.42.2-1.el9.x86_64                @@System
    Upgrade  selinux-policy-38.1.11-2.el9_2.3.noarch             @rhel-9-baseos-rhui-rpms
    Upgraded selinux-policy-38.1.11-2.el9_2.2.noarch             @@System
    Upgrade  kernel-tools-libs-5.14.0-284.18.1.el9_2.x86_64      @rhel-9-baseos-rhui-rpms
    Upgraded kernel-tools-libs-5.14.0-284.11.1.el9_2.x86_64      @@System
    Upgrade  krb5-libs-1.20.1-9.el9_2.x86_64                     @rhel-9-baseos-rhui-rpms
    Upgraded krb5-libs-1.20.1-8.el9.x86_64                       @@System
    Upgrade  systemd-udev-252-14.el9_2.1.x86_64                  @rhel-9-baseos-rhui-rpms
    Upgraded systemd-udev-252-13.el9_2.x86_64                    @@System
    Upgrade  NetworkManager-team-1:1.42.2-3.el9_2.x86_64         @rhel-9-baseos-rhui-rpms
    Upgraded NetworkManager-team-1:1.42.2-1.el9.x86_64           @@System
    Upgrade  systemd-pam-252-14.el9_2.1.x86_64                   @rhel-9-baseos-rhui-rpms
    Upgraded systemd-pam-252-13.el9_2.x86_64                     @@System
    Upgrade  openssl-libs-1:3.0.7-16.el9_2.x86_64                @rhel-9-baseos-rhui-rpms
    Upgraded openssl-libs-1:3.0.7-6.el9_2.x86_64                 @@System
    Upgrade  NetworkManager-tui-1:1.42.2-3.el9_2.x86_64          @rhel-9-baseos-rhui-rpms
    Upgraded NetworkManager-tui-1:1.42.2-1.el9.x86_64            @@System
    Upgrade  less-590-2.el9_2.x86_64                             @rhel-9-baseos-rhui-rpms
    Upgraded less-590-1.el9_0.x86_64                             @@System
    Upgrade  systemd-rpm-macros-252-14.el9_2.1.noarch            @rhel-9-baseos-rhui-rpms
    Upgraded systemd-rpm-macros-252-13.el9_2.noarch              @@System
    Upgrade  kernel-tools-5.14.0-284.18.1.el9_2.x86_64           @rhel-9-baseos-rhui-rpms
    Upgraded kernel-tools-5.14.0-284.11.1.el9_2.x86_64           @@System
    Upgrade  systemd-252-14.el9_2.1.x86_64                       @rhel-9-baseos-rhui-rpms
    Upgraded systemd-252-13.el9_2.x86_64                         @@System
    Upgrade  kexec-tools-2.0.25-13.el9_2.1.x86_64                @rhel-9-baseos-rhui-rpms
    Upgraded kexec-tools-2.0.25-13.el9_2.x86_64                  @@System
    Upgrade  NetworkManager-libnm-1:1.42.2-3.el9_2.x86_64        @rhel-9-baseos-rhui-rpms
    Upgraded NetworkManager-libnm-1:1.42.2-1.el9.x86_64          @@System
    Upgrade  systemd-libs-252-14.el9_2.1.x86_64                  @rhel-9-baseos-rhui-rpms
    Upgraded systemd-libs-252-13.el9_2.x86_64                    @@System
    Upgrade  rh-amazon-rhui-client-4.0.9-1.el9.noarch            @rhui-client-config-server-9
    Upgraded rh-amazon-rhui-client-4.0.6-1.el9.noarch            @@System
Scriptlet output:
   1 [INFO:choose_repo] choose_repo:33 2023-07-31 08:22:08,572: Enabling binary repos in redhat-rhui.repo
   2 [INFO:choose_repo] choose_repo:56 2023-07-31 08:22:08,581: Enabling client config repo
   3 [INFO:choose_repo] choose_repo:64 2023-07-31 08:22:08,581: Executing [sed -i 's/enabled=0/enabled=1/' /etc/yum.repos.d/redhat-rhui-client-config.repo]

インストールもしくはアップデートしたパッケージを確認できました。

ちなみにUpgradeはアップデート後のパッケージ名で、Upgradedはアップデート前のパッケージ名です。

dnf upgrade の実行履歴からインストール及びアップデート後のパッケージを抽出する

dnf upgradeの実行履歴からインストール及びアップデート後のパッケージを抽出してみましょう。

InstallもしくはUpgradeのパッケージ名を抽出するのでgrepやawkで頑張ります。

$ dnf history info 2 \
  | grep -E 'Install |Upgrade ' \
  | awk '{print $2}'
kernel-modules-5.14.0-284.18.1.el9_2.x86_64
kernel-core-5.14.0-284.18.1.el9_2.x86_64
kernel-5.14.0-284.18.1.el9_2.x86_64
kernel-modules-core-5.14.0-284.18.1.el9_2.x86_64
redhat-cloud-client-configuration-1-10.el9_0.noarch
python-unversioned-command-3.9.16-1.el9_2.1.noarch
insights-client-3.1.7-12.1.el9_2.noarch
NetworkManager-cloud-setup-1:1.42.2-3.el9_2.x86_64
iputils-20210202-8.el9_1.1.x86_64
c-ares-1.17.1-5.el9_2.1.x86_64
python3-3.9.16-1.el9_2.1.x86_64
python3-libs-3.9.16-1.el9_2.1.x86_64
microcode_ctl-4:20220809-2.20230214.1.el9_2.noarch
openssl-1:3.0.7-16.el9_2.x86_64
selinux-policy-targeted-38.1.11-2.el9_2.3.noarch
python3-perf-5.14.0-284.18.1.el9_2.x86_64
NetworkManager-1:1.42.2-3.el9_2.x86_64
selinux-policy-38.1.11-2.el9_2.3.noarch
kernel-tools-libs-5.14.0-284.18.1.el9_2.x86_64
krb5-libs-1.20.1-9.el9_2.x86_64
systemd-udev-252-14.el9_2.1.x86_64
NetworkManager-team-1:1.42.2-3.el9_2.x86_64
systemd-pam-252-14.el9_2.1.x86_64
openssl-libs-1:3.0.7-16.el9_2.x86_64
NetworkManager-tui-1:1.42.2-3.el9_2.x86_64
less-590-2.el9_2.x86_64
systemd-rpm-macros-252-14.el9_2.1.noarch
kernel-tools-5.14.0-284.18.1.el9_2.x86_64
systemd-252-14.el9_2.1.x86_64
kexec-tools-2.0.25-13.el9_2.1.x86_64
NetworkManager-libnm-1:1.42.2-3.el9_2.x86_64
systemd-libs-252-14.el9_2.1.x86_64
rh-amazon-rhui-client-4.0.9-1.el9.noarch

簡単に取得できましたね。

こちらのパッケージ名を指定してdnf upgradeできるか確認してみましょう。

以下記事でAWS上ではRHELリポジトリサーバーを構築してRPMパッケージを再配布するのは非推奨ということをお伝えしました。

加えて、RHEL 9はSSM Patch Managerでサポートされていません。

そのため、dnf upgradeの適用間隔が空いているが、適用するパッケージを揃えたい場合はパッケージ名を直接指定することになります。

dnf historyの結果を用いて楽をしてみましょう。

まずdnf upgradeでパッケージ名を指定するためにdnf historyの結果を整形します。

$ dnf history info 2 \
  | grep -E 'Install |Upgrade ' \
  | awk '{print "\t" $2 " \\"}'
        kernel-modules-5.14.0-284.18.1.el9_2.x86_64 \
        kernel-core-5.14.0-284.18.1.el9_2.x86_64 \
        kernel-5.14.0-284.18.1.el9_2.x86_64 \
        kernel-modules-core-5.14.0-284.18.1.el9_2.x86_64 \
        redhat-cloud-client-configuration-1-10.el9_0.noarch \
        python-unversioned-command-3.9.16-1.el9_2.1.noarch \
        insights-client-3.1.7-12.1.el9_2.noarch \
        NetworkManager-cloud-setup-1:1.42.2-3.el9_2.x86_64 \
        iputils-20210202-8.el9_1.1.x86_64 \
        c-ares-1.17.1-5.el9_2.1.x86_64 \
        python3-3.9.16-1.el9_2.1.x86_64 \
        python3-libs-3.9.16-1.el9_2.1.x86_64 \
        microcode_ctl-4:20220809-2.20230214.1.el9_2.noarch \
        openssl-1:3.0.7-16.el9_2.x86_64 \
        selinux-policy-targeted-38.1.11-2.el9_2.3.noarch \
        python3-perf-5.14.0-284.18.1.el9_2.x86_64 \
        NetworkManager-1:1.42.2-3.el9_2.x86_64 \
        selinux-policy-38.1.11-2.el9_2.3.noarch \
        kernel-tools-libs-5.14.0-284.18.1.el9_2.x86_64 \
        krb5-libs-1.20.1-9.el9_2.x86_64 \
        systemd-udev-252-14.el9_2.1.x86_64 \
        NetworkManager-team-1:1.42.2-3.el9_2.x86_64 \
        systemd-pam-252-14.el9_2.1.x86_64 \
        openssl-libs-1:3.0.7-16.el9_2.x86_64 \
        NetworkManager-tui-1:1.42.2-3.el9_2.x86_64 \
        less-590-2.el9_2.x86_64 \
        systemd-rpm-macros-252-14.el9_2.1.noarch \
        kernel-tools-5.14.0-284.18.1.el9_2.x86_64 \
        systemd-252-14.el9_2.1.x86_64 \
        kexec-tools-2.0.25-13.el9_2.1.x86_64 \
        NetworkManager-libnm-1:1.42.2-3.el9_2.x86_64 \
        systemd-libs-252-14.el9_2.1.x86_64 \
        rh-amazon-rhui-client-4.0.9-1.el9.noarch \

同じAMIを使って作成したRHEL 9.2にて、先ほど出力された結果を元にdnf upgradeを実行します。

$ sudo dnf upgrade \
        kernel-modules-5.14.0-284.18.1.el9_2.x86_64 \
        kernel-core-5.14.0-284.18.1.el9_2.x86_64 \
        kernel-5.14.0-284.18.1.el9_2.x86_64 \
        kernel-modules-core-5.14.0-284.18.1.el9_2.x86_64 \
        redhat-cloud-client-configuration-1-10.el9_0.noarch \
        python-unversioned-command-3.9.16-1.el9_2.1.noarch \
        insights-client-3.1.7-12.1.el9_2.noarch \
        NetworkManager-cloud-setup-1:1.42.2-3.el9_2.x86_64 \
        iputils-20210202-8.el9_1.1.x86_64 \
        c-ares-1.17.1-5.el9_2.1.x86_64 \
        python3-3.9.16-1.el9_2.1.x86_64 \
        python3-libs-3.9.16-1.el9_2.1.x86_64 \
        microcode_ctl-4:20220809-2.20230214.1.el9_2.noarch \
        openssl-1:3.0.7-16.el9_2.x86_64 \
        selinux-policy-targeted-38.1.11-2.el9_2.3.noarch \
        python3-perf-5.14.0-284.18.1.el9_2.x86_64 \
        NetworkManager-1:1.42.2-3.el9_2.x86_64 \
        selinux-policy-38.1.11-2.el9_2.3.noarch \
        kernel-tools-libs-5.14.0-284.18.1.el9_2.x86_64 \
        krb5-libs-1.20.1-9.el9_2.x86_64 \
        systemd-udev-252-14.el9_2.1.x86_64 \
        NetworkManager-team-1:1.42.2-3.el9_2.x86_64 \
        systemd-pam-252-14.el9_2.1.x86_64 \
        openssl-libs-1:3.0.7-16.el9_2.x86_64 \
        NetworkManager-tui-1:1.42.2-3.el9_2.x86_64 \
        less-590-2.el9_2.x86_64 \
        systemd-rpm-macros-252-14.el9_2.1.noarch \
        kernel-tools-5.14.0-284.18.1.el9_2.x86_64 \
        systemd-252-14.el9_2.1.x86_64 \
        kexec-tools-2.0.25-13.el9_2.1.x86_64 \
        NetworkManager-libnm-1:1.42.2-3.el9_2.x86_64 \
        systemd-libs-252-14.el9_2.1.x86_64 \
        rh-amazon-rhui-client-4.0.9-1.el9.noarch
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Red Hat Enterprise Linux 9 for x86_64 - AppStream from RHUI (RPMs)                                                    30 kB/s | 4.5 kB     00:00
Red Hat Enterprise Linux 9 for x86_64 - BaseOS from RHUI (RPMs)                                                       41 kB/s | 4.1 kB     00:00
Red Hat Enterprise Linux 9 Client Configuration                                                                       42 kB/s | 2.0 kB     00:00
Dependencies resolved.
=====================================================================================================================================================
 Package                                     Architecture     Version                                    Repository                             Size
=====================================================================================================================================================
Installing:
 kernel                                      x86_64           5.14.0-284.18.1.el9_2                      rhel-9-baseos-rhui-rpms               3.4 M
 kernel-core                                 x86_64           5.14.0-284.18.1.el9_2                      rhel-9-baseos-rhui-rpms                17 M
 kernel-modules                              x86_64           5.14.0-284.18.1.el9_2                      rhel-9-baseos-rhui-rpms                37 M
 kernel-modules-core                         x86_64           5.14.0-284.18.1.el9_2                      rhel-9-baseos-rhui-rpms                36 M
Upgrading:
 NetworkManager                              x86_64           1:1.42.2-3.el9_2                           rhel-9-baseos-rhui-rpms               2.2 M
 NetworkManager-cloud-setup                  x86_64           1:1.42.2-3.el9_2                           rhel-9-appstream-rhui-rpms             73 k
 NetworkManager-libnm                        x86_64           1:1.42.2-3.el9_2                           rhel-9-baseos-rhui-rpms               1.8 M
 NetworkManager-team                         x86_64           1:1.42.2-3.el9_2                           rhel-9-baseos-rhui-rpms                39 k
 NetworkManager-tui                          x86_64           1:1.42.2-3.el9_2                           rhel-9-baseos-rhui-rpms               243 k
 c-ares                                      x86_64           1.17.1-5.el9_2.1                           rhel-9-baseos-rhui-rpms               106 k
 insights-client                             noarch           3.1.7-12.1.el9_2                           rhel-9-appstream-rhui-rpms            1.2 M
 iputils                                     x86_64           20210202-8.el9_1.1                         rhel-9-baseos-rhui-rpms               178 k
 kernel-tools                                x86_64           5.14.0-284.18.1.el9_2                      rhel-9-baseos-rhui-rpms               3.7 M
 kernel-tools-libs                           x86_64           5.14.0-284.18.1.el9_2                      rhel-9-baseos-rhui-rpms               3.4 M
 kexec-tools                                 x86_64           2.0.25-13.el9_2.1                          rhel-9-baseos-rhui-rpms               499 k
 krb5-libs                                   x86_64           1.20.1-9.el9_2                             rhel-9-baseos-rhui-rpms               731 k
 less                                        x86_64           590-2.el9_2                                rhel-9-baseos-rhui-rpms               166 k
 microcode_ctl                               noarch           4:20220809-2.20230214.1.el9_2              rhel-9-baseos-rhui-rpms               7.5 M
 openssl                                     x86_64           1:3.0.7-16.el9_2                           rhel-9-baseos-rhui-rpms               1.2 M
 openssl-libs                                x86_64           1:3.0.7-16.el9_2                           rhel-9-baseos-rhui-rpms               2.2 M
 python-unversioned-command                  noarch           3.9.16-1.el9_2.1                           rhel-9-appstream-rhui-rpms             11 k
 python3                                     x86_64           3.9.16-1.el9_2.1                           rhel-9-baseos-rhui-rpms                30 k
 python3-libs                                x86_64           3.9.16-1.el9_2.1                           rhel-9-baseos-rhui-rpms               7.8 M
 python3-perf                                x86_64           5.14.0-284.18.1.el9_2                      rhel-9-baseos-rhui-rpms               3.6 M
 redhat-cloud-client-configuration           noarch           1-10.el9_0                                 rhel-9-appstream-rhui-rpms             20 k
 rh-amazon-rhui-client                       noarch           4.0.9-1.el9                                rhui-client-config-server-9            38 k
 selinux-policy                              noarch           38.1.11-2.el9_2.3                          rhel-9-baseos-rhui-rpms                56 k
 selinux-policy-targeted                     noarch           38.1.11-2.el9_2.3                          rhel-9-baseos-rhui-rpms               6.8 M
 systemd                                     x86_64           252-14.el9_2.1                             rhel-9-baseos-rhui-rpms               4.1 M
 systemd-libs                                x86_64           252-14.el9_2.1                             rhel-9-baseos-rhui-rpms               652 k
 systemd-pam                                 x86_64           252-14.el9_2.1                             rhel-9-baseos-rhui-rpms               257 k
 systemd-rpm-macros                          noarch           252-14.el9_2.1                             rhel-9-baseos-rhui-rpms                45 k
 systemd-udev                                x86_64           252-14.el9_2.1                             rhel-9-baseos-rhui-rpms               1.9 M

Transaction Summary
=====================================================================================================================================================
Install   4 Packages
Upgrade  29 Packages

Total download size: 144 M
Is this ok [y/N]: y
Downloading Packages:
(1/33): kernel-5.14.0-284.18.1.el9_2.x86_64.rpm                                                                       15 MB/s | 3.4 MB     00:00
(2/33): kernel-core-5.14.0-284.18.1.el9_2.x86_64.rpm                                                                  14 MB/s |  17 MB     00:01
(3/33): redhat-cloud-client-configuration-1-10.el9_0.noarch.rpm                                                      1.7 MB/s |  20 kB     00:00
.
.
(中略)
.
.
Installed products updated.

Upgraded:
  NetworkManager-1:1.42.2-3.el9_2.x86_64                                    NetworkManager-cloud-setup-1:1.42.2-3.el9_2.x86_64
  NetworkManager-libnm-1:1.42.2-3.el9_2.x86_64                              NetworkManager-team-1:1.42.2-3.el9_2.x86_64
  NetworkManager-tui-1:1.42.2-3.el9_2.x86_64                                c-ares-1.17.1-5.el9_2.1.x86_64
  insights-client-3.1.7-12.1.el9_2.noarch                                   iputils-20210202-8.el9_1.1.x86_64
  kernel-tools-5.14.0-284.18.1.el9_2.x86_64                                 kernel-tools-libs-5.14.0-284.18.1.el9_2.x86_64
  kexec-tools-2.0.25-13.el9_2.1.x86_64                                      krb5-libs-1.20.1-9.el9_2.x86_64
  less-590-2.el9_2.x86_64                                                   microcode_ctl-4:20220809-2.20230214.1.el9_2.noarch
  openssl-1:3.0.7-16.el9_2.x86_64                                           openssl-libs-1:3.0.7-16.el9_2.x86_64
  python-unversioned-command-3.9.16-1.el9_2.1.noarch                        python3-3.9.16-1.el9_2.1.x86_64
  python3-libs-3.9.16-1.el9_2.1.x86_64                                      python3-perf-5.14.0-284.18.1.el9_2.x86_64
  redhat-cloud-client-configuration-1-10.el9_0.noarch                       rh-amazon-rhui-client-4.0.9-1.el9.noarch
  selinux-policy-38.1.11-2.el9_2.3.noarch                                   selinux-policy-targeted-38.1.11-2.el9_2.3.noarch
  systemd-252-14.el9_2.1.x86_64                                             systemd-libs-252-14.el9_2.1.x86_64
  systemd-pam-252-14.el9_2.1.x86_64                                         systemd-rpm-macros-252-14.el9_2.1.noarch
  systemd-udev-252-14.el9_2.1.x86_64
Installed:
  kernel-5.14.0-284.18.1.el9_2.x86_64                  kernel-core-5.14.0-284.18.1.el9_2.x86_64     kernel-modules-5.14.0-284.18.1.el9_2.x86_64
  kernel-modules-core-5.14.0-284.18.1.el9_2.x86_64

Complete!

問題なくアップデートできました。

dnf historyで実行結果を確認してみましょう。

$ dnf history
Not root, Subscription Management repositories not updated
ID     | Command line                                                                                   | Date and time    | Action(s)      | Altered
-----------------------------------------------------------------------------------------------------------------------------------------------------
     2 | upgrade kernel-modules-5.14.0-284.18.1.el9_2.x86_64 kernel-core-5.14.0-284.18.1.el9_2.x86_64 k | 2023-07-31 08:48 | I, U           |   33 E<
     1 | install -y https://s3.us-east-1.amazonaws.com/amazon-ssm-us-east-1/latest/linux_amd64/amazon-s | 2023-07-31 08:23 | Install        |    1 >E

$ dnf history info 2
Not root, Subscription Management repositories not updated
Transaction ID : 2
Begin time     : Mon 31 Jul 2023 08:48:51 AM UTC
Begin rpmdb    : f34e25944d058cec12f7960c930f3cf1de6368785a851b2b87c8bfe43e32da9a
End time       : Mon 31 Jul 2023 08:53:33 AM UTC (282 seconds)
End rpmdb      : 69ca116624ec87ad7efda16d43a3b448830f7f5a65528125898f569bdf5d5536
User           : System <unset>
Return-Code    : Success
Releasever     : 9
Command Line   : upgrade kernel-modules-5.14.0-284.18.1.el9_2.x86_64 kernel-core-5.14.0-284.18.1.el9_2.x86_64 kernel-5.14.0-284.18.1.el9_2.x86_64 kernel-modules-core-5.14.0-284.18.1.el9_2.x86_64 redhat-cloud-client-configuration-1-10.el9_0.noarch python-unversioned-command-3.9.16-1.el9_2.1.noarchinsights-client-3.1.7-12.1.el9_2.noarch NetworkManager-cloud-setup-1:1.42.2-3.el9_2.x86_64 iputils-20210202-8.el9_1.1.x86_64 c-ares-1.17.1-5.el9_2.1.x86_64 python3-3.9.16-1.el9_2.1.x86_64 python3-libs-3.9.16-1.el9_2.1.x86_64 microcode_ctl-4:20220809-2.20230214.1.el9_2.noarch openssl-1:3.0.7-16.el9_2.x86_64 selinux-policy-targeted-38.1.11-2.el9_2.3.noarch python3-perf-5.14.0-284.18.1.el9_2.x86_64 NetworkManager-1:1.42.2-3.el9_2.x86_64 selinux-policy-38.1.11-2.el9_2.3.noarch kernel-tools-libs-5.14.0-284.18.1.el9_2.x86_64 krb5-libs-1.20.1-9.el9_2.x86_64 systemd-udev-252-14.el9_2.1.x86_64 NetworkManager-team-1:1.42.2-3.el9_2.x86_64 systemd-pam-252-14.el9_2.1.x86_64 openssl-libs-1:3.0.7-16.el9_2.x86_64 NetworkManager-tui-1:1.42.2-3.el9_2.x86_64 less-590-2.el9_2.x86_64 systemd-rpm-macros-252-14.el9_2.1.noarch kernel-tools-5.14.0-284.18.1.el9_2.x86_64 systemd-252-14.el9_2.1.x86_64 kexec-tools-2.0.25-13.el9_2.1.x86_64 NetworkManager-libnm-1:1.42.2-3.el9_2.x86_64 systemd-libs-252-14.el9_2.1.x86_64 rh-amazon-rhui-client-4.0.9-1.el9.noarch
Comment        :
Packages Altered:
    Install  kernel-modules-5.14.0-284.18.1.el9_2.x86_64         @rhel-9-baseos-rhui-rpms
    Install  kernel-core-5.14.0-284.18.1.el9_2.x86_64            @rhel-9-baseos-rhui-rpms
    Install  kernel-5.14.0-284.18.1.el9_2.x86_64                 @rhel-9-baseos-rhui-rpms
    Install  kernel-modules-core-5.14.0-284.18.1.el9_2.x86_64    @rhel-9-baseos-rhui-rpms
    Upgrade  redhat-cloud-client-configuration-1-10.el9_0.noarch @rhel-9-appstream-rhui-rpms
    Upgraded redhat-cloud-client-configuration-1-10.el9.noarch   @@System
    Upgrade  python-unversioned-command-3.9.16-1.el9_2.1.noarch  @rhel-9-appstream-rhui-rpms
    Upgraded python-unversioned-command-3.9.16-1.el9.noarch      @@System
    Upgrade  insights-client-3.1.7-12.1.el9_2.noarch             @rhel-9-appstream-rhui-rpms
    Upgraded insights-client-3.1.7-12.el9.noarch                 @@System
    Upgrade  NetworkManager-cloud-setup-1:1.42.2-3.el9_2.x86_64  @rhel-9-appstream-rhui-rpms
    Upgraded NetworkManager-cloud-setup-1:1.42.2-1.el9.x86_64    @@System
    Upgrade  iputils-20210202-8.el9_1.1.x86_64                   @rhel-9-baseos-rhui-rpms
    Upgraded iputils-20210202-8.el9.x86_64                       @@System
    Upgrade  c-ares-1.17.1-5.el9_2.1.x86_64                      @rhel-9-baseos-rhui-rpms
    Upgraded c-ares-1.17.1-5.el9.x86_64                          @@System
    Upgrade  python3-3.9.16-1.el9_2.1.x86_64                     @rhel-9-baseos-rhui-rpms
    Upgraded python3-3.9.16-1.el9.x86_64                         @@System
    Upgrade  python3-libs-3.9.16-1.el9_2.1.x86_64                @rhel-9-baseos-rhui-rpms
    Upgraded python3-libs-3.9.16-1.el9.x86_64                    @@System
    Upgrade  microcode_ctl-4:20220809-2.20230214.1.el9_2.noarch  @rhel-9-baseos-rhui-rpms
    Upgraded microcode_ctl-4:20220809-2.el9.noarch               @@System
    Upgrade  openssl-1:3.0.7-16.el9_2.x86_64                     @rhel-9-baseos-rhui-rpms
    Upgraded openssl-1:3.0.7-6.el9_2.x86_64                      @@System
    Upgrade  selinux-policy-targeted-38.1.11-2.el9_2.3.noarch    @rhel-9-baseos-rhui-rpms
    Upgraded selinux-policy-targeted-38.1.11-2.el9_2.2.noarch    @@System
    Upgrade  python3-perf-5.14.0-284.18.1.el9_2.x86_64           @rhel-9-baseos-rhui-rpms
    Upgraded python3-perf-5.14.0-284.11.1.el9_2.x86_64           @@System
    Upgrade  NetworkManager-1:1.42.2-3.el9_2.x86_64              @rhel-9-baseos-rhui-rpms
    Upgraded NetworkManager-1:1.42.2-1.el9.x86_64                @@System
    Upgrade  selinux-policy-38.1.11-2.el9_2.3.noarch             @rhel-9-baseos-rhui-rpms
    Upgraded selinux-policy-38.1.11-2.el9_2.2.noarch             @@System
    Upgrade  kernel-tools-libs-5.14.0-284.18.1.el9_2.x86_64      @rhel-9-baseos-rhui-rpms
    Upgraded kernel-tools-libs-5.14.0-284.11.1.el9_2.x86_64      @@System
    Upgrade  krb5-libs-1.20.1-9.el9_2.x86_64                     @rhel-9-baseos-rhui-rpms
    Upgraded krb5-libs-1.20.1-8.el9.x86_64                       @@System
    Upgrade  systemd-udev-252-14.el9_2.1.x86_64                  @rhel-9-baseos-rhui-rpms
    Upgraded systemd-udev-252-13.el9_2.x86_64                    @@System
    Upgrade  NetworkManager-team-1:1.42.2-3.el9_2.x86_64         @rhel-9-baseos-rhui-rpms
    Upgraded NetworkManager-team-1:1.42.2-1.el9.x86_64           @@System
    Upgrade  systemd-pam-252-14.el9_2.1.x86_64                   @rhel-9-baseos-rhui-rpms
    Upgraded systemd-pam-252-13.el9_2.x86_64                     @@System
    Upgrade  openssl-libs-1:3.0.7-16.el9_2.x86_64                @rhel-9-baseos-rhui-rpms
    Upgraded openssl-libs-1:3.0.7-6.el9_2.x86_64                 @@System
    Upgrade  NetworkManager-tui-1:1.42.2-3.el9_2.x86_64          @rhel-9-baseos-rhui-rpms
    Upgraded NetworkManager-tui-1:1.42.2-1.el9.x86_64            @@System
    Upgrade  less-590-2.el9_2.x86_64                             @rhel-9-baseos-rhui-rpms
    Upgraded less-590-1.el9_0.x86_64                             @@System
    Upgrade  systemd-rpm-macros-252-14.el9_2.1.noarch            @rhel-9-baseos-rhui-rpms
    Upgraded systemd-rpm-macros-252-13.el9_2.noarch              @@System
    Upgrade  kernel-tools-5.14.0-284.18.1.el9_2.x86_64           @rhel-9-baseos-rhui-rpms
    Upgraded kernel-tools-5.14.0-284.11.1.el9_2.x86_64           @@System
    Upgrade  systemd-252-14.el9_2.1.x86_64                       @rhel-9-baseos-rhui-rpms
    Upgraded systemd-252-13.el9_2.x86_64                         @@System
    Upgrade  kexec-tools-2.0.25-13.el9_2.1.x86_64                @rhel-9-baseos-rhui-rpms
    Upgraded kexec-tools-2.0.25-13.el9_2.x86_64                  @@System
    Upgrade  NetworkManager-libnm-1:1.42.2-3.el9_2.x86_64        @rhel-9-baseos-rhui-rpms
    Upgraded NetworkManager-libnm-1:1.42.2-1.el9.x86_64          @@System
    Upgrade  systemd-libs-252-14.el9_2.1.x86_64                  @rhel-9-baseos-rhui-rpms
    Upgraded systemd-libs-252-13.el9_2.x86_64                    @@System
    Upgrade  rh-amazon-rhui-client-4.0.9-1.el9.noarch            @rhui-client-config-server-9
    Upgraded rh-amazon-rhui-client-4.0.6-1.el9.noarch            @@System
Scriptlet output:
   1 [INFO:choose_repo] choose_repo:33 2023-07-31 08:50:16,372: Enabling binary repos in redhat-rhui.repo
   2 [INFO:choose_repo] choose_repo:56 2023-07-31 08:50:16,374: Enabling client config repo
   3 [INFO:choose_repo] choose_repo:64 2023-07-31 08:50:16,374: Executing [sed -i 's/enabled=0/enabled=1/' /etc/yum.repos.d/redhat-rhui-client-config.repo]

Command Lineに指定したパッケージ名が表示されていますね。

dnf install したものを取り消す

dnf history undoをすることで指定した実行結果(トランザクション)を取り消すことが可能です。

実際にやってみましょう。

まず、適当にNginxをインストールします。

$ sudo dnf install nginx -y
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Last metadata expiration check: 0:21:35 ago on Mon 31 Jul 2023 09:09:56 AM UTC.
Dependencies resolved.
=====================================================================================================================================================
 Package                              Architecture             Version                            Repository                                    Size
=====================================================================================================================================================
Installing:
 nginx                                x86_64                   1:1.20.1-14.el9                    rhel-9-appstream-rhui-rpms                    43 k
Installing dependencies:
 nginx-core                           x86_64                   1:1.20.1-14.el9                    rhel-9-appstream-rhui-rpms                   576 k
 nginx-filesystem                     noarch                   1:1.20.1-14.el9                    rhel-9-appstream-rhui-rpms                    13 k
 redhat-logos-httpd                   noarch                   90.4-1.el9                         rhel-9-appstream-rhui-rpms                    18 k

Transaction Summary
=====================================================================================================================================================
Install  4 Packages

Total download size: 650 k
Installed size: 1.8 M
Downloading Packages:
(1/4): nginx-filesystem-1.20.1-14.el9.noarch.rpm                                                                     295 kB/s |  13 kB     00:00
(2/4): redhat-logos-httpd-90.4-1.el9.noarch.rpm                                                                      378 kB/s |  18 kB     00:00
.
.
(中略)
.
.
Installed:
  nginx-1:1.20.1-14.el9.x86_64   nginx-core-1:1.20.1-14.el9.x86_64   nginx-filesystem-1:1.20.1-14.el9.noarch   redhat-logos-httpd-90.4-1.el9.noarch

Complete!

$ nginx -v
nginx version: nginx/1.20.1

インストール後、dnfの実行履歴を確認します。

$ dnf history
Not root, Subscription Management repositories not updated
ID     | Command line                                                                                   | Date and time    | Action(s)      | Altered
-----------------------------------------------------------------------------------------------------------------------------------------------------
     3 | install nginx -y                                                                               | 2023-07-31 09:31 | Install        |    4
     2 | upgrade                                                                                        | 2023-07-31 08:21 | I, U           |   33 E<
     1 | install -y https://s3.us-east-1.amazonaws.com/amazon-ssm-us-east-1/latest/linux_amd64/amazon-s | 2023-07-31 08:17 | Install        |    1 >E

$ dnf history info 3
Not root, Subscription Management repositories not updated
Transaction ID : 3
Begin time     : Mon 31 Jul 2023 09:31:32 AM UTC
Begin rpmdb    : 7dad51b1cbad6c54f36cb461b7e40302f5a1c428a8be7151e22eedddb68e4482
End time       : Mon 31 Jul 2023 09:31:33 AM UTC (1 seconds)
End rpmdb      : c0b03beeb9327ddb24cea6fc5e44561fd414e79333e21db7a54d84135f659ae4
User           : System <unset>
Return-Code    : Success
Releasever     : 9
Command Line   : install nginx -y
Comment        :
Packages Altered:
    Install redhat-logos-httpd-90.4-1.el9.noarch    @rhel-9-appstream-rhui-rpms
    Install nginx-filesystem-1:1.20.1-14.el9.noarch @rhel-9-appstream-rhui-rpms
    Install nginx-core-1:1.20.1-14.el9.x86_64       @rhel-9-appstream-rhui-rpms
    Install nginx-1:1.20.1-14.el9.x86_64            @rhel-9-appstream-rhui-rpms

Nginxをインストールした時のIDを指定してdnf history undoを行います。

$ sudo dnf history undo 3
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Last metadata expiration check: 0:25:24 ago on Mon 31 Jul 2023 09:09:56 AM UTC.
Dependencies resolved.
=====================================================================================================================================================
 Package                              Architecture             Version                           Repository                                     Size
=====================================================================================================================================================
Removing:
 nginx                                x86_64                   1:1.20.1-14.el9                   @rhel-9-appstream-rhui-rpms                   148 k
Removing dependent packages:
 nginx-core                           x86_64                   1:1.20.1-14.el9                   @rhel-9-appstream-rhui-rpms                   1.6 M
 nginx-filesystem                     noarch                   1:1.20.1-14.el9                   @rhel-9-appstream-rhui-rpms                     0
 redhat-logos-httpd                   noarch                   90.4-1.el9                        @rhel-9-appstream-rhui-rpms                    12 k

Transaction Summary
=====================================================================================================================================================
Remove  4 Packages

Freed space: 1.8 M
Is this ok [y/N]: y
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                             1/1
  Running scriptlet: nginx-1:1.20.1-14.el9.x86_64                                                                                                1/4
  Erasing          : nginx-1:1.20.1-14.el9.x86_64                                                                                                1/4
  Running scriptlet: nginx-1:1.20.1-14.el9.x86_64                                                                                                1/4
  Erasing          : redhat-logos-httpd-90.4-1.el9.noarch                                                                                        2/4
  Erasing          : nginx-core-1:1.20.1-14.el9.x86_64                                                                                           3/4
  Erasing          : nginx-filesystem-1:1.20.1-14.el9.noarch                                                                                     4/4
  Running scriptlet: nginx-filesystem-1:1.20.1-14.el9.noarch                                                                                     4/4
  Verifying        : nginx-1:1.20.1-14.el9.x86_64                                                                                                1/4
  Verifying        : nginx-core-1:1.20.1-14.el9.x86_64                                                                                           2/4
  Verifying        : nginx-filesystem-1:1.20.1-14.el9.noarch                                                                                     3/4
  Verifying        : redhat-logos-httpd-90.4-1.el9.noarch                                                                                        4/4
Installed products updated.

Removed:
  nginx-1:1.20.1-14.el9.x86_64   nginx-core-1:1.20.1-14.el9.x86_64   nginx-filesystem-1:1.20.1-14.el9.noarch   redhat-logos-httpd-90.4-1.el9.noarch

Complete!

$ nginx -v
bash: /usr/sbin/nginx: No such file or directory

インストールの取り消しなので、アンインストールされましたね。

実行履歴を確認してみます。

$ dnf history
Not root, Subscription Management repositories not updated
ID     | Command line                                                                                   | Date and time    | Action(s)      | Altered
-----------------------------------------------------------------------------------------------------------------------------------------------------
     4 | history undo 3                                                                                 | 2023-07-31 09:36 | Removed        |    4
     3 | install nginx -y                                                                               | 2023-07-31 09:31 | Install        |    4
     2 | upgrade                                                                                        | 2023-07-31 08:21 | I, U           |   33 E<
     1 | install -y https://s3.us-east-1.amazonaws.com/amazon-ssm-us-east-1/latest/linux_amd64/amazon-s | 2023-07-31 08:17 | Install        |    1 >E

$ dnf history info 4
Not root, Subscription Management repositories not updated
Transaction ID : 4
Begin time     : Mon 31 Jul 2023 09:36:00 AM UTC
Begin rpmdb    : c0b03beeb9327ddb24cea6fc5e44561fd414e79333e21db7a54d84135f659ae4
End time       : Mon 31 Jul 2023 09:36:01 AM UTC (1 seconds)
End rpmdb      : 7dad51b1cbad6c54f36cb461b7e40302f5a1c428a8be7151e22eedddb68e4482
User           : System <unset>
Return-Code    : Success
Releasever     : 9
Command Line   : history undo 3
Comment        :
Packages Altered:
    Removed nginx-1:1.20.1-14.el9.x86_64            @@System
    Removed nginx-core-1:1.20.1-14.el9.x86_64       @@System
    Removed nginx-filesystem-1:1.20.1-14.el9.noarch @@System
    Removed redhat-logos-httpd-90.4-1.el9.noarch    @@System

Removedとなっていることが分かります。

dnf install を再実行する

再実行(redo)することも可能です。

Nginxのインストールを再実行してみます。

$ sudo dnf history redo 3
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Last metadata expiration check: 0:29:12 ago on Mon 31 Jul 2023 09:09:56 AM UTC.
Dependencies resolved.
=====================================================================================================================================================
 Package                              Architecture             Version                            Repository                                    Size
=====================================================================================================================================================
Installing:
 nginx                                x86_64                   1:1.20.1-14.el9                    rhel-9-appstream-rhui-rpms                    43 k
Installing dependencies:
 nginx-core                           x86_64                   1:1.20.1-14.el9                    rhel-9-appstream-rhui-rpms                   576 k
 nginx-filesystem                     noarch                   1:1.20.1-14.el9                    rhel-9-appstream-rhui-rpms                    13 k
 redhat-logos-httpd                   noarch                   90.4-1.el9                         rhel-9-appstream-rhui-rpms                    18 k

Transaction Summary
=====================================================================================================================================================
Install  4 Packages

Total download size: 650 k
Installed size: 1.8 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): redhat-logos-httpd-90.4-1.el9.noarch.rpm                                                                      396 kB/s |  18 kB     00:00
(2/4): nginx-filesystem-1.20.1-14.el9.noarch.rpm                                                                     274 kB/s |  13 kB     00:00
.
.
(中略)
.
.
Installed:
  nginx-1:1.20.1-14.el9.x86_64   nginx-core-1:1.20.1-14.el9.x86_64   nginx-filesystem-1:1.20.1-14.el9.noarch   redhat-logos-httpd-90.4-1.el9.noarch

Complete!

インストールが完了しました。

実行履歴を確認します。

$ dnf history
Not root, Subscription Management repositories not updated
ID     | Command line                                                                                   | Date and time    | Action(s)      | Altered
-----------------------------------------------------------------------------------------------------------------------------------------------------
     5 | history redo 3                                                                                 | 2023-07-31 09:39 | Install        |    4
     4 | history undo 3                                                                                 | 2023-07-31 09:36 | Removed        |    4
     3 | install nginx -y                                                                               | 2023-07-31 09:31 | Install        |    4
     2 | upgrade                                                                                        | 2023-07-31 08:21 | I, U           |   33 E<
     1 | install -y https://s3.us-east-1.amazonaws.com/amazon-ssm-us-east-1/latest/linux_amd64/amazon-s | 2023-07-31 08:17 | Install        |    1 >E

ID 5のActionがInstallとなっていますね。

redoしたものをundoすることも可能です。

$ sudo dnf history undo 5
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Last metadata expiration check: 0:31:20 ago on Mon 31 Jul 2023 09:09:56 AM UTC.
Dependencies resolved.
=====================================================================================================================================================
 Package                              Architecture             Version                           Repository                                     Size
=====================================================================================================================================================
Removing:
 nginx                                x86_64                   1:1.20.1-14.el9                   @rhel-9-appstream-rhui-rpms                   148 k
Removing dependent packages:
 nginx-core                           x86_64                   1:1.20.1-14.el9                   @rhel-9-appstream-rhui-rpms                   1.6 M
 nginx-filesystem                     noarch                   1:1.20.1-14.el9                   @rhel-9-appstream-rhui-rpms                     0
 redhat-logos-httpd                   noarch                   90.4-1.el9                        @rhel-9-appstream-rhui-rpms                    12 k

Transaction Summary
=====================================================================================================================================================
Remove  4 Packages

Freed space: 1.8 M
Is this ok [y/N]: y
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                             1/1
  Running scriptlet: nginx-1:1.20.1-14.el9.x86_64                                                                                                1/4
  Erasing          : nginx-1:1.20.1-14.el9.x86_64                                                                                                1/4
  Running scriptlet: nginx-1:1.20.1-14.el9.x86_64                                                                                                1/4
  Erasing          : redhat-logos-httpd-90.4-1.el9.noarch                                                                                        2/4
  Erasing          : nginx-core-1:1.20.1-14.el9.x86_64                                                                                           3/4
  Erasing          : nginx-filesystem-1:1.20.1-14.el9.noarch                                                                                     4/4
  Running scriptlet: nginx-filesystem-1:1.20.1-14.el9.noarch                                                                                     4/4
  Verifying        : nginx-1:1.20.1-14.el9.x86_64                                                                                                1/4
  Verifying        : nginx-core-1:1.20.1-14.el9.x86_64                                                                                           2/4
  Verifying        : nginx-filesystem-1:1.20.1-14.el9.noarch                                                                                     3/4
  Verifying        : redhat-logos-httpd-90.4-1.el9.noarch                                                                                        4/4
Installed products updated.

Removed:
  nginx-1:1.20.1-14.el9.x86_64   nginx-core-1:1.20.1-14.el9.x86_64   nginx-filesystem-1:1.20.1-14.el9.noarch   redhat-logos-httpd-90.4-1.el9.noarch

Complete!

$ dnf history
Not root, Subscription Management repositories not updated
ID     | Command line                                                                                   | Date and time    | Action(s)      | Altered
-----------------------------------------------------------------------------------------------------------------------------------------------------
     6 | history undo 5                                                                                 | 2023-07-31 09:41 | Removed        |    4
     5 | history redo 3                                                                                 | 2023-07-31 09:39 | Install        |    4
     4 | history undo 3                                                                                 | 2023-07-31 09:36 | Removed        |    4
     3 | install nginx -y                                                                               | 2023-07-31 09:31 | Install        |    4
     2 | upgrade                                                                                        | 2023-07-31 08:21 | I, U           |   33 E<
     1 | install -y https://s3.us-east-1.amazonaws.com/amazon-ssm-us-east-1/latest/linux_amd64/amazon-s | 2023-07-31 08:17 | Install        |    1 >E

Removedされました。

複数のトランザクションを取り消す

dnf history rollbackで複数のトランザクションを取り消すことも可能です。

httpdとNginxをインストールします。

$ sudo dnf install httpd -y
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Last metadata expiration check: 3:18:15 ago on Mon 31 Jul 2023 09:09:56 AM UTC.
Dependencies resolved.
=====================================================================================================================================================
 Package                             Architecture            Version                               Repository                                   Size
=====================================================================================================================================================
Installing:
 httpd                               x86_64                  2.4.53-11.el9_2.5                     rhel-9-appstream-rhui-rpms                   53 k
Installing dependencies:
 apr                                 x86_64                  1.7.0-11.el9                          rhel-9-appstream-rhui-rpms                  127 k
 apr-util                            x86_64                  1.6.1-20.el9_2.1                      rhel-9-appstream-rhui-rpms                   97 k
 apr-util-bdb                        x86_64                  1.6.1-20.el9_2.1                      rhel-9-appstream-rhui-rpms                   14 k
 httpd-core                          x86_64                  2.4.53-11.el9_2.5                     rhel-9-appstream-rhui-rpms                  1.5 M
 httpd-filesystem                    noarch                  2.4.53-11.el9_2.5                     rhel-9-appstream-rhui-rpms                   17 k
 httpd-tools                         x86_64                  2.4.53-11.el9_2.5                     rhel-9-appstream-rhui-rpms                   87 k
 mailcap                             noarch                  2.1.49-5.el9                          rhel-9-baseos-rhui-rpms                      35 k
 redhat-logos-httpd                  noarch                  90.4-1.el9                            rhel-9-appstream-rhui-rpms                   18 k
Installing weak dependencies:
 apr-util-openssl                    x86_64                  1.6.1-20.el9_2.1                      rhel-9-appstream-rhui-rpms                   16 k
 mod_http2                           x86_64                  1.15.19-4.el9_2.4                     rhel-9-appstream-rhui-rpms                  153 k
 mod_lua                             x86_64                  2.4.53-11.el9_2.5                     rhel-9-appstream-rhui-rpms                   63 k

Transaction Summary
=====================================================================================================================================================
Install  12 Packages

Total download size: 2.2 M
Installed size: 6.0 M
Downloading Packages:
(1/12): apr-1.7.0-11.el9.x86_64.rpm                                                                                  1.9 MB/s | 127 kB     00:00
(2/12): redhat-logos-httpd-90.4-1.el9.noarch.rpm                                                                     270 kB/s |  18 kB     00:00
.
.
(中略)
.
.
Installed:
  apr-1.7.0-11.el9.x86_64                             apr-util-1.6.1-20.el9_2.1.x86_64               apr-util-bdb-1.6.1-20.el9_2.1.x86_64
  apr-util-openssl-1.6.1-20.el9_2.1.x86_64            httpd-2.4.53-11.el9_2.5.x86_64                 httpd-core-2.4.53-11.el9_2.5.x86_64
  httpd-filesystem-2.4.53-11.el9_2.5.noarch           httpd-tools-2.4.53-11.el9_2.5.x86_64           mailcap-2.1.49-5.el9.noarch
  mod_http2-1.15.19-4.el9_2.4.x86_64                  mod_lua-2.4.53-11.el9_2.5.x86_64               redhat-logos-httpd-90.4-1.el9.noarch

Complete!

$ sudo dnf install nginx -y
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Last metadata expiration check: 3:19:42 ago on Mon 31 Jul 2023 09:09:56 AM UTC.
Dependencies resolved.
=====================================================================================================================================================
 Package                            Architecture             Version                              Repository                                    Size
=====================================================================================================================================================
Installing:
 nginx                              x86_64                   1:1.20.1-14.el9                      rhel-9-appstream-rhui-rpms                    43 k
Installing dependencies:
 nginx-core                         x86_64                   1:1.20.1-14.el9                      rhel-9-appstream-rhui-rpms                   576 k
 nginx-filesystem                   noarch                   1:1.20.1-14.el9                      rhel-9-appstream-rhui-rpms                    13 k

Transaction Summary
=====================================================================================================================================================
Install  3 Packages

Total download size: 632 k
Installed size: 1.7 M
Downloading Packages:
(1/3): nginx-1.20.1-14.el9.x86_64.rpm                                                                                674 kB/s |  43 kB     00:00
(2/3): nginx-filesystem-1.20.1-14.el9.noarch.rpm                                                                     202 kB/s |  13 kB     00:00
.
.
(中略)
.
.
Installed:
  nginx-1:1.20.1-14.el9.x86_64                nginx-core-1:1.20.1-14.el9.x86_64                nginx-filesystem-1:1.20.1-14.el9.noarch

Complete!

$ dnf history
Not root, Subscription Management repositories not updated
ID     | Command line                                                                                   | Date and time    | Action(s)      | Altered
-----------------------------------------------------------------------------------------------------------------------------------------------------
     8 | install nginx -y                                                                               | 2023-07-31 12:29 | Install        |    3
     7 | install httpd -y                                                                               | 2023-07-31 12:28 | Install        |   12
     6 | history undo 5                                                                                 | 2023-07-31 09:41 | Removed        |    4
     5 | history redo 3                                                                                 | 2023-07-31 09:39 | Install        |    4
     4 | history undo 3                                                                                 | 2023-07-31 09:36 | Removed        |    4
     3 | install nginx -y                                                                               | 2023-07-31 09:31 | Install        |    4
     2 | upgrade                                                                                        | 2023-07-31 08:21 | I, U           |   33 E<
     1 | install -y https://s3.us-east-1.amazonaws.com/amazon-ssm-us-east-1/latest/linux_amd64/amazon-s | 2023-07-31 08:17 | Install        |    1 >E

インストール完了後、ID 6の状態、つまりはhttpdをインストールする前までのトランザクションを取り消します。

$ sudo dnf history rollback 7
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Last metadata expiration check: 3:20:19 ago on Mon 31 Jul 2023 09:09:56 AM UTC.
Dependencies resolved.
=====================================================================================================================================================
 Package                            Architecture             Version                             Repository                                     Size
=====================================================================================================================================================
Removing:
 nginx                              x86_64                   1:1.20.1-14.el9                     @rhel-9-appstream-rhui-rpms                   148 k
Removing dependent packages:
 nginx-core                         x86_64                   1:1.20.1-14.el9                     @rhel-9-appstream-rhui-rpms                   1.6 M
 nginx-filesystem                   noarch                   1:1.20.1-14.el9                     @rhel-9-appstream-rhui-rpms                     0

Transaction Summary
=====================================================================================================================================================
Remove  3 Packages

Freed space: 1.7 M
Is this ok [y/N]: N
Operation aborted.
[ec2-user@ip-172-31-25-161 ~]$
[ec2-user@ip-172-31-25-161 ~]$ sudo dnf history rollback 6
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Last metadata expiration check: 3:20:30 ago on Mon 31 Jul 2023 09:09:56 AM UTC.
Dependencies resolved.
=====================================================================================================================================================
 Package                             Architecture            Version                              Repository                                    Size
=====================================================================================================================================================
Removing:
 apr-util-openssl                    x86_64                  1.6.1-20.el9_2.1                     @rhel-9-appstream-rhui-rpms                   23 k
 httpd                               x86_64                  2.4.53-11.el9_2.5                    @rhel-9-appstream-rhui-rpms                   59 k
 mod_http2                           x86_64                  1.15.19-4.el9_2.4                    @rhel-9-appstream-rhui-rpms                  385 k
 mod_lua                             x86_64                  2.4.53-11.el9_2.5                    @rhel-9-appstream-rhui-rpms                  142 k
 nginx                               x86_64                  1:1.20.1-14.el9                      @rhel-9-appstream-rhui-rpms                  148 k
Removing dependent packages:
 apr                                 x86_64                  1.7.0-11.el9                         @rhel-9-appstream-rhui-rpms                  289 k
 apr-util                            x86_64                  1.6.1-20.el9_2.1                     @rhel-9-appstream-rhui-rpms                  211 k
 apr-util-bdb                        x86_64                  1.6.1-20.el9_2.1                     @rhel-9-appstream-rhui-rpms                   15 k
 httpd-core                          x86_64                  2.4.53-11.el9_2.5                    @rhel-9-appstream-rhui-rpms                  4.6 M
 httpd-filesystem                    noarch                  2.4.53-11.el9_2.5                    @rhel-9-appstream-rhui-rpms                  400
 httpd-tools                         x86_64                  2.4.53-11.el9_2.5                    @rhel-9-appstream-rhui-rpms                  198 k
 mailcap                             noarch                  2.1.49-5.el9                         @rhel-9-baseos-rhui-rpms                      78 k
 nginx-core                          x86_64                  1:1.20.1-14.el9                      @rhel-9-appstream-rhui-rpms                  1.6 M
 nginx-filesystem                    noarch                  1:1.20.1-14.el9                      @rhel-9-appstream-rhui-rpms                    0
 redhat-logos-httpd                  noarch                  90.4-1.el9                           @rhel-9-appstream-rhui-rpms                   12 k

Transaction Summary
=====================================================================================================================================================
Remove  15 Packages

Freed space: 7.7 M
Is this ok [y/N]: y
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                             1/1
.
.
(中略)
.
.
Removed:
  apr-1.7.0-11.el9.x86_64                            apr-util-1.6.1-20.el9_2.1.x86_64                 apr-util-bdb-1.6.1-20.el9_2.1.x86_64
  apr-util-openssl-1.6.1-20.el9_2.1.x86_64           httpd-2.4.53-11.el9_2.5.x86_64                   httpd-core-2.4.53-11.el9_2.5.x86_64
  httpd-filesystem-2.4.53-11.el9_2.5.noarch          httpd-tools-2.4.53-11.el9_2.5.x86_64             mailcap-2.1.49-5.el9.noarch
  mod_http2-1.15.19-4.el9_2.4.x86_64                 mod_lua-2.4.53-11.el9_2.5.x86_64                 nginx-1:1.20.1-14.el9.x86_64
  nginx-core-1:1.20.1-14.el9.x86_64                  nginx-filesystem-1:1.20.1-14.el9.noarch          redhat-logos-httpd-90.4-1.el9.noarch

Complete!

$ dnf history
Not root, Subscription Management repositories not updated
ID     | Command line                                                                                   | Date and time    | Action(s)      | Altered
-----------------------------------------------------------------------------------------------------------------------------------------------------
     9 | history rollback 6                                                                             | 2023-07-31 12:30 | Removed        |   15
     8 | install nginx -y                                                                               | 2023-07-31 12:29 | Install        |    3
     7 | install httpd -y                                                                               | 2023-07-31 12:28 | Install        |   12
     6 | history undo 5                                                                                 | 2023-07-31 09:41 | Removed        |    4
     5 | history redo 3                                                                                 | 2023-07-31 09:39 | Install        |    4
     4 | history undo 3                                                                                 | 2023-07-31 09:36 | Removed        |    4
     3 | install nginx -y                                                                               | 2023-07-31 09:31 | Install        |    4
     2 | upgrade                                                                                        | 2023-07-31 08:21 | I, U           |   33 E<
     1 | install -y https://s3.us-east-1.amazonaws.com/amazon-ssm-us-east-1/latest/linux_amd64/amazon-s | 2023-07-31 08:17 | Install        |    1 >E

$ dnf history info 9
Not root, Subscription Management repositories not updated
Transaction ID : 9
Begin time     : Mon 31 Jul 2023 12:30:41 PM UTC
Begin rpmdb    : 5858cb563433cf4678f84243e4f16be635f44be6b1168ec37ae20b9c3dc9dd12
End time       : Mon 31 Jul 2023 12:30:42 PM UTC (1 seconds)
End rpmdb      : 7dad51b1cbad6c54f36cb461b7e40302f5a1c428a8be7151e22eedddb68e4482
User           : System <unset>
Return-Code    : Success
Releasever     : 9
Command Line   : history rollback 6
Comment        :
Packages Altered:
    Removed apr-1.7.0-11.el9.x86_64                   @@System
    Removed apr-util-1.6.1-20.el9_2.1.x86_64          @@System
    Removed apr-util-bdb-1.6.1-20.el9_2.1.x86_64      @@System
    Removed apr-util-openssl-1.6.1-20.el9_2.1.x86_64  @@System
    Removed httpd-2.4.53-11.el9_2.5.x86_64            @@System
    Removed httpd-core-2.4.53-11.el9_2.5.x86_64       @@System
    Removed httpd-filesystem-2.4.53-11.el9_2.5.noarch @@System
    Removed httpd-tools-2.4.53-11.el9_2.5.x86_64      @@System
    Removed mailcap-2.1.49-5.el9.noarch               @@System
    Removed mod_http2-1.15.19-4.el9_2.4.x86_64        @@System
    Removed mod_lua-2.4.53-11.el9_2.5.x86_64          @@System
    Removed nginx-1:1.20.1-14.el9.x86_64              @@System
    Removed nginx-core-1:1.20.1-14.el9.x86_64         @@System
    Removed nginx-filesystem-1:1.20.1-14.el9.noarch   @@System
    Removed redhat-logos-httpd-90.4-1.el9.noarch      @@System

httpdとNginxのインストールが取り消されました。

ターミナルのログをロストしてしまっても絶望しなくて済む

dnf でインストールやアップデートした履歴を確認してみました。

トランザクションとして記録されているので、ターミナルのログをロストしてしまっても、「何をいつアップデートしたのか分からず絶望する」といったことにならずに済みます。

トランザクションの簡単に取り消しも可能なので、間違えてインストールしてしまった時のロールバックにも使いやすいですね。

この記事が誰かの助けになれば幸いです。

以上、AWS事業本部 コンサルティング部の のんピ(@non____97)でした!