如何使用 YUM 历史命令

[ad_1]

您是否曾经想查看过去的更新或回滚破坏您的站点或对服务器操作的某些方面产生负面影响的更新? 好吧,您可以使用 yum history 命令轻松完成此操作。

让我们从 yum history 命令的基本语法及其参数开始:

[email protected]:~# yum history
[email protected]:~# yum history <command> #ID
[email protected]:~# yum history [options]
[email protected]:~# history [info|list|packages-list|summary|addon-info|redo|undo|rollback|new]

在本文中,我们将主要关注 history 命令的这四个子命令:

  • 列表
  • 重做
  • 撤销
  • 回滚

参数详情

yum history 命令包含几个可用的子命令。 下面是这些子命令可以做什么的简要列表。

  • 信息 – 提供有关上次更新或您指定的更新 ID 的详细信息。
  • 列表 – 提供过去更新的列表。
  • 包列表 – 获取包名称,并提供访问该包的所有更新 ID 的列表。
  • 包信息 – 获取包名称并为当前服务器提供该包的历史更新信息。
  • 概括 – 摘要提供了过去三个月内发生的所有交易的概览。
  • 插件信息 – 查看有关交易 ID 的任何其他信息。
  • 重做 – 此命令重复在特定事务 ID 中完成的工作。
  • 撤消 – 此命令撤销先前在特定事务 ID 中完成的工作。
  • 回滚 – 此命令将 RPM 回滚到它们以前的配置。 此选项可以对多个事务而不是单个 ID 进行回滚。
  • 新的 – 清除当前的 yum 历史记录以提供一个全新的空白历史文件。 (只有在 yumdb/rpmdb 有问题时才使用它。)
  • 同步 – 将为任何已安装软件包存储的 rpmdb/yumdb 数据更新为 repo 中的当前数据。
  • 统计数据 – 提供有关当前历史数据库的统计信息。

百胜历史“列表”

让我们首先回顾一下 list 子命令。 当您使用命令“yum history list”或仅使用“yum history”命令时,您可以看到类似下面列出的输出的详细信息:

[[email protected] [~]$ yum history
Loaded plugins: fastestmirror, priorities, universal-hooks
ID 	| Command line 	| Date and time	| Action(s) | Altered
----------------------------------------------------------------------
15 | --assumeyes --config /et 	| 2020-01-22 14:09 	| I, U 	| 84
14 | update -y 	| 2020-01-21 11:18 	| Update 	| 1
13 | update -y 	| 2020-01-19 11:18 	| Update 	| 2
12 | install jwhois | 2020-01-17 15:51 	| Install 	| 2
11 | update -y 	| 2020-01-13 11:18 	| Update 	| 6 <
10 | update -y 	| 2020-01-07 11:18 	| Update 	| 1 >  
9| --assumeyes --config /et | 2020-01-02 14:09 	| Update | 1
8 | update -y 	| 2019-12-25 11:18 	| Update 	| 1
7 | update -y 	| 2019-12-19 11:18 	| Update 	| 76
6 | update -y 	| 2019-12-18 11:18 	| Update 	| 1 E<
5 | update -y 	| 2019-12-13 11:18 	| Update 	| 8 >
4 | install vim | 2019-12-10 20:02 	| Install 	| 1 ##
3 | remove vim 	| 2019-12-10 20:02 	| Erase 	| 1 EE

此命令为我们提供了自 yum 历史记录初始化以来在服务器上实现的所有不同安装/卸载的摘要。 在上面“history list”命令的输出中,您会注意到“Altered”列以“>”、“

以下是 yum 联机帮助页中确定的这些符号的含义及其含义的详细摘要。

> - The rpmdb was changed, outside yum, after the transaction.
< - The rpmdb was changed, outside yum, before the transaction.
* - The transaction aborted before completion.
# - The transaction completed, but with a non-zero status.
E - The transaction completed fine, but had warning/error output during the transaction.
P - The transaction completed fine, but problems already existed in the rpmdb.
s - The transaction completed fine, but --skip-broken was enabled and had to skip some packages.

从该表中列出的信息中,您可以看到单独的交易以及它们的详细信息。 此处要注意的重要信息是列表中提供的 ID 号。 这些数字以及如何使用它们将在下一个命令中进一步详细说明。

百胜历史“回滚”

接下来,我们将回顾“yum rollback”命令选项。 此命令比可用的“撤消”选项具有更多的多功能性。 回滚选项基本上允许我们将所有已发生的更新完全恢复到特定的 ID 号。 下面是此选项的一个有用示例。 我们已经在两个独立的事务中安装了 vim 和 vim-go。

[[email protected] [~]$ yum history
Loaded plugins: fastestmirror, priorities, universal-hooks
ID | Command line       | Date and time   | Action(s)   | Altered
----------------------------------------------------------------------
17 | install vim-go 	| 2020-01-23 04:18 	| Install 	| 5
16 | install vim 	| 2020-01-23 04:16 	| Install 	| 1
15 | --assumeyes --config /et 	| 2020-01-22 14:09  | I, U 	| 84

现在,如果我们运行命令“yum history rollback 15”,您会注意到它会将 yum install 所做的早期更改还原为它们之前在事务 15 上的显示方式。

[[email protected] [~]$ yum history rollback 15
Loaded plugins: fastestmirror, priorities, universal-hooks
Rollback to transaction 15, from Wed Jan 22 14:09:53 2020
 Undoing the following transactions: 16, 17
 Dep-Install golang-1.13.3-1.el7.x86_64 	@epel
 Dep-Install golang-bin-1.13.3-1.el7.x86_64 	@epel
 Dep-Install golang-src-1.13.3-1.el7.noarch 	@epel
 Dep-Install mercurial-2.6.2-10.el7.x86_64 	@system-base
 Install 	vim-enhanced-2:7.4.629-6.el7.x86_64 @system-base
 Install 	vim-go-1.8-3.el7.x86_64 	@epel
Resolving Dependencies
--> Running transaction check
---> Package golang.x86_64 0:1.13.3-1.el7 will be erased
---> Package golang-bin.x86_64 0:1.13.3-1.el7 will be erased
---> Package golang-src.noarch 0:1.13.3-1.el7 will be erased
---> Package mercurial.x86_64 0:2.6.2-10.el7 will be erased
---> Package vim-enhanced.x86_64 2:7.4.629-6.el7 will be erased
---> Package vim-go.x86_64 0:1.8-3.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================
 Package		Arch		Version		Repository		Size
=====================================================================
Removing:
 Golang	      x86_64	1.13.3-1.el7	@epel	7.8 M
 Golang-bin   x86_64	1.13.3-1.el7	@epel	249 M
 Golang-src   noarch	1.13.3-1.el7	@epel	48 M
 Mercurial    x86_64	2.6.2-10.el7	@system-base	12 M
 Vim-enhanced x86_64	2:7.4.629-6.el7	@system-base	2.2 M
 Vim-go	      x86_64	1.8-3.el7	@epel	234 k

Transaction Summary
=====================================================================
Remove 6 Packages

Installed size: 319 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 Erasing : vim-go-1.8-3.el7.x86_64		1/6
 Erasing : golang-bin-1.13.3-1.el7.x86_64	2/6
 Erasing : golang-1.13.3-1.el7.x86_64	3/6
 Erasing : golang-src-1.13.3-1.el7.noarch	4/6
 Erasing : mercurial-2.6.2-10.el7.x86_64	5/6
 Erasing : 2:vim-enhanced-7.4.629-6.el7.x86_64 6/6
 Verifying : 2:vim-enhanced-7.4.629-6.el7.x86_64 1/6
 Verifying : golang-src-1.13.3-1.el7.noarch 2/6
 Verifying : vim-go-1.8-3.el7.x86_64 3/6
 Verifying : golang-1.13.3-1.el7.x86_64 4/6
 Verifying : golang-bin-1.13.3-1.el7.x86_64 5/6
 Verifying : mercurial-2.6.2-10.el7.x86_64 6/6

Removed:
golang.x86_64 0:1.13.3-1.el7 golang-bin.x86_64 0:1.13.3-1.el7 golang-src.noarch 0:1.13.3-1.el7 mercurial.x86_64 0:2.6.2-10.el7 vim-enhanced.x86_64 2:7.4.629-6.el7 vim-go.x86_64 0:1.8-3.el7

Complete!

如您所见,上述命令删除了 vim 和 vim-go 安装,以及所有相关的依赖项。

百胜历史“重做”

现在,使用我们卸载 vim 和 vim go 的最后一个示例,我们可以使用“yum redo”命令从上面的历史记录表中指出的事务 ID #16 重新安装 vim。

[[email protected] [~]$ yum history redo 16
Loaded plugins: fastestmirror, priorities, universal-hooks
Repeating transaction 16, from Thu Jan 23 04:16:11 2020
 Install vim-enhanced-2:7.4.629-6.el7.x86_64 @system-base
Loading mirror speeds from cached hostfile
 * EA4: 208.100.0.204
 * cpanel-addons-production-feed: 208.100.0.204
 * cpanel-plugins: 208.100.0.204
 * epel: mirrors.CodePre.com
201 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package vim-enhanced.x86_64 2:7.4.629-6.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================
 Package	Arch	Version		Repository		Size
=====================================================================
Installing: Vim-enhanced 
               x86_64	2:7.4.629-6.el7	system-base		1.1 M
Transaction Summary
=====================================================================
Install 1 Package

Total download size: 1.1 M
Installed size: 2.2 M
Is this ok [y/d/N]: y
Downloading packages:
Vim-enhanced-7.4.629-6.el7.x86_64.rpm		1.1 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 Installing : 2:vim-enhanced-7.4.629-6.el7.x86_64		1/1
 Verifying : 2:vim-enhanced-7.4.629-6.el7.x86_64		1/1

Installed:
 vim-enhanced.x86_64 2:7.4.629-6.el7

Complete!

如您所见,yum 命令加载了事务并重新安装了 vim。 这个命令很方便,因为它会尝试安装当时使用的确切版本。 如果您尝试将安装回滚到特定版本号或重新安装旧版本的软件,则首选“重做”选项。

百胜历史“撤消”

与上面提到的回滚命令非常相似,我们将扩展最后一个事务并演示“历史撤销”命令的功能。 要撤消操作,我们需要使用要恢复的事务的特定“ID”号运行“yum history undo”命令。

[[email protected] [~]$ yum history undo 16
Loaded plugins: fastestmirror, priorities, universal-hooks
Undoing transaction 16, from Thu Jan 23 04:16:11 2020
 Install vim-enhanced-2:7.4.629-6.el7.x86_64 @system-base
Resolving Dependencies
--> Running transaction check
---> Package vim-enhanced.x86_64 2:7.4.629-6.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================
 Package 	Arch 	Version 	Repository 	Size
=====================================================================
Removing:
 vim-enhanced 	x86_64 	2:7.4.629-6.el7 @system-base 	2.2 M

Transaction Summary
=====================================================================
Remove 1 Package

Installed size: 2.2 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 Erasing	: 2:vim-enhanced-7.4.629-6.el7.x86_64 	1/1
 Verifying : 2:vim-enhanced-7.4.629-6.el7.x86_64 	1/1

Removed:
 vim-enhanced.x86_64 2:7.4.629-6.el7

Complete!

就是这样! 这是如何使用“yum history”命令运行“undo”选项的一个很好的例子。

结论

我们已经列出了我们的安装历史,回滚了一个更新,重新安装了以前版本的 vim,最后,取消了更新的安装。 最后,我们将再次显示历史列表,以便您查看今天发生了哪些变化以及它们的样子。

[[email protected] [/]$ yum history list
Loaded plugins: fastestmirror, priorities, universal-hooks
ID 	| Command line 		| Date and time	| Action(s) 	| Altered
----------------------------------------------------------------------
20 | history undo 16 	 | 2020-01-23 04:56 | Erase   | 1 
19 | history redo 16 	 | 2020-01-23 04:42 | Install | 1 
18 | history rollback 15 | 2020-01-23 04:27 | Erase   | 6 EE
17 | install vim-go 	 | 2020-01-23 04:18 | Install | 5 
16 | install vim         | 2020-01-23 04:16 | Install | 1 
15 | --assumeyes --config /et 	| 2020-01-22 14:09 | I, U | 84 
14 | update -y           | 2020-01-21 11:18 | Update  | 1  

我们希望有关 yum history 命令的这些信息可以更轻松地跟踪和纠正您可能遇到的任何更新/安装问题。

我们等待您的来电!

如果您的服务器或系统遇到任何问题,我们的专业支持团队可以提供有关此主题的信息以及更多信息。

如果您遇到任何类型的问题,让您停下来,只需拨打 800.580.4985 给我们打电话,或打开一个 聊天 或与我们联系的一张票,与我们知识渊博的支持技术人员交谈,以了解您今天如何利用这些技术!

[ad_2]

Related Posts