apt-get upgrade
如果您不喜欢结果,在Ubuntu中有没有办法回滚或撤消上一次升级?
apt-get upgrade
如果您不喜欢结果,在Ubuntu中有没有办法回滚或撤消上一次升级?
Answers:
aptitude
根据Debian软件包管理,您可以访问软件包的所有版本。
我遇到了Hartman的Blogstatic博客:如何在Ubuntu Lucid中撤消更新
撤消有问题的更新的第一步是找出确切的更新。在搜索了一些论坛之后,我遇到了一种查看更新历史的方法:打开突触包管理器(在终端中为“ sudo synaptic”)。在菜单栏中,单击文件->历史记录,您将看到所有更新按日期排序。
不幸的是,我今天已经安装了大约20个更新,但我不知道是哪个引起了问题。通过搜索“历史记录”列表中命名的每个软件包,我可以一次降级几个软件包,直到问题解决并确定了有问题的更新。去做这个:
使用搜索栏找到要降级的软件包。找到要查找的内容后,单击包装以将其选中。在菜单栏中,单击软件包->强制版本,然后从下拉菜单中选择软件包的先前版本。单击“应用”按钮以应用降级。
我今天必须在Debian系统上执行此操作。首先,我确定了有问题的升级发生的时间范围,并检索了给出升级包的新旧版本号的日志条目:
$ awk '$1=="2016-03-20" && $3=="upgrade"' /var/log/dpkg.log
2016-03-20 16:58:22 upgrade libwebkitgtk-3.0-0:amd64 2.4.9-3 2.4.10-1
2016-03-20 16:58:24 upgrade libjavascriptcoregtk-3.0-0:amd64 2.4.9-3 2.4.10-1
2016-03-20 16:58:26 upgrade traceroute:amd64 1:2.0.22-1 1:2.1.0-1
2016-03-20 16:58:33 upgrade ethtool:amd64 1:4.2-1 1:4.5-1
2016-03-20 16:58:34 upgrade libsdl1.2debian:amd64 1.2.15+dfsg1-3 1.2.15+dfsg1-4
2016-03-20 16:58:34 upgrade subversion:amd64 1.9.3-2+b1 1.9.3-3
2016-03-20 16:58:36 upgrade libsvn1:amd64 1.9.3-2+b1 1.9.3-3
2016-03-20 16:58:56 upgrade linux-image-amd64:amd64 4.3+70 4.4+71
2016-03-20 16:58:56 upgrade linux-libc-dev:amd64 4.3.5-1 4.4.6-1
2016-03-20 16:59:03 upgrade amd64-microcode:amd64 2.20141028.1 2.20160316.1
接下来,我尝试在磁盘上找到仍在缓存的软件包文件(幸运的是,我没有运行autoclean):
$ awk '$1=="2016-03-20" && $3=="upgrade" {gsub(/:/, "%3a", $5); split($4, f, ":"); print "/var/cache/apt/archives/" f[1] "_" $5 "_" f[2] ".deb"}' /var/log/dpkg.log | xargs -r ls -ld
ls: cannot access '/var/cache/apt/archives/ethtool_1%3a4.2-1_amd64.deb': No such file or directory
-rw-r--r-- 1 root root 28820 Dec 18 2014 /var/cache/apt/archives/amd64-microcode_2.20141028.1_amd64.deb
-rw-r--r-- 1 root root 1978874 Dec 10 18:22 /var/cache/apt/archives/libjavascriptcoregtk-3.0-0_2.4.9-3_amd64.deb
-rw-r--r-- 1 root root 185006 Mar 12 00:41 /var/cache/apt/archives/libsdl1.2debian_1.2.15+dfsg1-3_amd64.deb
-rw-r--r-- 1 root root 1317644 Mar 3 11:30 /var/cache/apt/archives/libsvn1_1.9.3-2+b1_amd64.deb
-rw-r--r-- 1 root root 7679400 Dec 10 18:22 /var/cache/apt/archives/libwebkitgtk-3.0-0_2.4.9-3_amd64.deb
-rw-r--r-- 1 root root 6108 Dec 14 06:59 /var/cache/apt/archives/linux-image-amd64_4.3+70_amd64.deb
-rw-r--r-- 1 root root 1075506 Feb 7 21:36 /var/cache/apt/archives/linux-libc-dev_4.3.5-1_amd64.deb
-rw-r--r-- 1 root root 983174 Mar 3 11:30 /var/cache/apt/archives/subversion_1.9.3-2+b1_amd64.deb
-rw-r--r-- 1 root root 53376 Feb 28 18:35 /var/cache/apt/archives/traceroute_1%3a2.0.22-1_amd64.deb
出于某种原因,我似乎没有较旧的ethtool软件包。尽管如此,让我们继续通过强制安装较早的软件包文件来进行操作:
$ sudo dpkg -i /var/cache/apt/archives/amd64-microcode_2.20141028.1_amd64.deb /var/cache/apt/archives/libjavascriptcoregtk-3.0-0_2.4.9-3_amd64.deb /var/cache/apt/archives/libsdl1.2debian_1.2.15+dfsg1-3_amd64.deb /var/cache/apt/archives/libsvn1_1.9.3-2+b1_amd64.deb /var/cache/apt/archives/libwebkitgtk-3.0-0_2.4.9-3_amd64.deb /var/cache/apt/archives/linux-image-amd64_4.3+70_amd64.deb /var/cache/apt/archives/linux-libc-dev_4.3.5-1_amd64.deb /var/cache/apt/archives/subversion_1.9.3-2+b1_amd64.deb /var/cache/apt/archives/traceroute_1%3a2.0.22-1_amd64.deb
dpkg: warning: downgrading amd64-microcode from 2.20160316.1 to 2.20141028.1
(Reading database ... 139632 files and directories currently installed.)
Preparing to unpack .../amd64-microcode_2.20141028.1_amd64.deb ...
Unpacking amd64-microcode (2.20141028.1) over (2.20160316.1) ...
dpkg: warning: downgrading libjavascriptcoregtk-3.0-0:amd64 from 2.4.10-1 to 2.4.9-3
Preparing to unpack .../libjavascriptcoregtk-3.0-0_2.4.9-3_amd64.deb ...
Unpacking libjavascriptcoregtk-3.0-0:amd64 (2.4.9-3) over (2.4.10-1) ...
dpkg: warning: downgrading libsdl1.2debian:amd64 from 1.2.15+dfsg1-4 to 1.2.15+dfsg1-3
Preparing to unpack .../libsdl1.2debian_1.2.15+dfsg1-3_amd64.deb ...
Unpacking libsdl1.2debian:amd64 (1.2.15+dfsg1-3) over (1.2.15+dfsg1-4) ...
dpkg: warning: downgrading libsvn1:amd64 from 1.9.3-3 to 1.9.3-2+b1
Preparing to unpack .../libsvn1_1.9.3-2+b1_amd64.deb ...
Unpacking libsvn1:amd64 (1.9.3-2+b1) over (1.9.3-3) ...
Preparing to unpack .../libwebkitgtk-3.0-0_2.4.9-3_amd64.deb ...
Unpacking libwebkitgtk-3.0-0:amd64 (2.4.9-3) over (2.4.9-3) ...
dpkg: warning: downgrading linux-image-amd64 from 4.4+71 to 4.3+70
Preparing to unpack .../linux-image-amd64_4.3+70_amd64.deb ...
Unpacking linux-image-amd64 (4.3+70) over (4.4+71) ...
dpkg: warning: downgrading linux-libc-dev:amd64 from 4.4.6-1 to 4.3.5-1
Preparing to unpack .../linux-libc-dev_4.3.5-1_amd64.deb ...
Unpacking linux-libc-dev:amd64 (4.3.5-1) over (4.4.6-1) ...
dpkg: warning: downgrading subversion from 1.9.3-3 to 1.9.3-2+b1
Preparing to unpack .../subversion_1.9.3-2+b1_amd64.deb ...
Unpacking subversion (1.9.3-2+b1) over (1.9.3-3) ...
dpkg: warning: downgrading traceroute from 1:2.1.0-1 to 1:2.0.22-1
Preparing to unpack .../traceroute_1%3a2.0.22-1_amd64.deb ...
Unpacking traceroute (1:2.0.22-1) over (1:2.1.0-1) ...
Setting up amd64-microcode (2.20141028.1) ...
update-initramfs: deferring update (trigger activated)
amd64-microcode: microcode will be updated at next boot
Setting up libjavascriptcoregtk-3.0-0:amd64 (2.4.9-3) ...
Setting up libsdl1.2debian:amd64 (1.2.15+dfsg1-3) ...
Setting up libsvn1:amd64 (1.9.3-2+b1) ...
dpkg: dependency problems prevent configuration of libwebkitgtk-3.0-0:amd64:
libwebkitgtk-3.0-0:amd64 depends on libwebkitgtk-3.0-common (>= 2.4.9); however:
Package libwebkitgtk-3.0-common is not installed.
dpkg: error processing package libwebkitgtk-3.0-0:amd64 (--install):
dependency problems - leaving unconfigured
Setting up linux-image-amd64 (4.3+70) ...
Setting up linux-libc-dev:amd64 (4.3.5-1) ...
Setting up subversion (1.9.3-2+b1) ...
Setting up traceroute (1:2.0.22-1) ...
update-alternatives: using /usr/bin/traceroute.db to provide /usr/bin/traceroute (traceroute) in auto mode
update-alternatives: using /usr/bin/lft.db to provide /usr/bin/lft (lft) in auto mode
update-alternatives: using /usr/bin/traceproto.db to provide /usr/bin/traceproto (traceproto) in auto mode
update-alternatives: using /usr/sbin/tcptraceroute.db to provide /usr/sbin/tcptraceroute (tcptraceroute) in auto mode
Processing triggers for libc-bin (2.22-3) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for initramfs-tools (0.123) ...
update-initramfs: Generating /boot/initrd.img-4.4.0-1-amd64
Errors were encountered while processing:
libwebkitgtk-3.0-0:amd64
如错误消息所述,我的一个软件包在升级之前就依赖于-common软件包,但是升级将其删除(并且apt-get找不到了)。幸运的是,它的软件包文件仍在/ var / cache / apt中,因此我可以将其添加到列表中,然后重试:
$ ls -ld /var/cache/apt/archives/libwebkitgtk-3.0-common*
-rw-r--r-- 1 root root 452278 Dec 10 18:22 /var/cache/apt/archives/libwebkitgtk-3.0-common_2.4.9-3_all.deb
$ sudo dpkg -i /var/cache/apt/archives/amd64-microcode_2.20141028.1_amd64.deb /var/cache/apt/archives/libjavascriptcoregtk-3.0-0_2.4.9-3_amd64.deb /var/cache/apt/archives/libsdl1.2debian_1.2.15+dfsg1-3_amd64.deb /var/cache/apt/archives/libsvn1_1.9.3-2+b1_amd64.deb /var/cache/apt/archives/libwebkitgtk-3.0-0_2.4.9-3_amd64.deb /var/cache/apt/archives/linux-image-amd64_4.3+70_amd64.deb /var/cache/apt/archives/linux-libc-dev_4.3.5-1_amd64.deb /var/cache/apt/archives/subversion_1.9.3-2+b1_amd64.deb /var/cache/apt/archives/traceroute_1%3a2.0.22-1_amd64.deb /var/cache/apt/archives/libwebkitgtk-3.0-common_2.4.9-3_all.deb
(Reading database ... 139632 files and directories currently installed.)
Preparing to unpack .../amd64-microcode_2.20141028.1_amd64.deb ...
Unpacking amd64-microcode (2.20141028.1) over (2.20141028.1) ...
Preparing to unpack .../libjavascriptcoregtk-3.0-0_2.4.9-3_amd64.deb ...
Unpacking libjavascriptcoregtk-3.0-0:amd64 (2.4.9-3) over (2.4.9-3) ...
Preparing to unpack .../libsdl1.2debian_1.2.15+dfsg1-3_amd64.deb ...
Unpacking libsdl1.2debian:amd64 (1.2.15+dfsg1-3) over (1.2.15+dfsg1-3) ...
Preparing to unpack .../libsvn1_1.9.3-2+b1_amd64.deb ...
Unpacking libsvn1:amd64 (1.9.3-2+b1) over (1.9.3-2+b1) ...
Preparing to unpack .../libwebkitgtk-3.0-0_2.4.9-3_amd64.deb ...
Unpacking libwebkitgtk-3.0-0:amd64 (2.4.9-3) over (2.4.9-3) ...
Preparing to unpack .../linux-image-amd64_4.3+70_amd64.deb ...
Unpacking linux-image-amd64 (4.3+70) over (4.3+70) ...
Preparing to unpack .../linux-libc-dev_4.3.5-1_amd64.deb ...
Unpacking linux-libc-dev:amd64 (4.3.5-1) over (4.3.5-1) ...
Preparing to unpack .../subversion_1.9.3-2+b1_amd64.deb ...
Unpacking subversion (1.9.3-2+b1) over (1.9.3-2+b1) ...
Preparing to unpack .../traceroute_1%3a2.0.22-1_amd64.deb ...
Unpacking traceroute (1:2.0.22-1) over (1:2.0.22-1) ...
Selecting previously unselected package libwebkitgtk-3.0-common.
Preparing to unpack .../libwebkitgtk-3.0-common_2.4.9-3_all.deb ...
Unpacking libwebkitgtk-3.0-common (2.4.9-3) ...
Setting up amd64-microcode (2.20141028.1) ...
update-initramfs: deferring update (trigger activated)
amd64-microcode: microcode will be updated at next boot
Setting up libjavascriptcoregtk-3.0-0:amd64 (2.4.9-3) ...
Setting up libsdl1.2debian:amd64 (1.2.15+dfsg1-3) ...
Setting up libsvn1:amd64 (1.9.3-2+b1) ...
Setting up linux-image-amd64 (4.3+70) ...
Setting up linux-libc-dev:amd64 (4.3.5-1) ...
Setting up subversion (1.9.3-2+b1) ...
Setting up traceroute (1:2.0.22-1) ...
update-alternatives: using /usr/bin/traceroute.db to provide /usr/bin/traceroute (traceroute) in auto mode
update-alternatives: using /usr/bin/lft.db to provide /usr/bin/lft (lft) in auto mode
update-alternatives: using /usr/bin/traceproto.db to provide /usr/bin/traceproto (traceproto) in auto mode
update-alternatives: using /usr/sbin/tcptraceroute.db to provide /usr/sbin/tcptraceroute (tcptraceroute) in auto mode
Setting up libwebkitgtk-3.0-common (2.4.9-3) ...
Setting up libwebkitgtk-3.0-0:amd64 (2.4.9-3) ...
Processing triggers for libc-bin (2.22-3) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for initramfs-tools (0.123) ...
update-initramfs: Generating /boot/initrd.img-4.4.0-1-amd64
成功!实际上,这并不能解决我的问题。但是它成功降级了软件包QED。
今天,我还不得不撤消了一些Debian服务器上的软件包升级。我使用aptitute成功地将软件包还原到了最新版本,而以下awk命令却非常有用。
(在以下命令中,将日期字符串替换为要还原升级的日期的日期)
awk 'BEGIN{ start="0" } { if($0 ~ /Log started: 2017-06-20/) { start="1"} if ( start == "1" && $0 ~ /Unpacking.*over/) {gsub(/[\s\t)( ]+/,"",$5); printf("%s=%s ", $2 , $5)}}' /var/log/apt/term.log
查看输出以确认这些是要还原的软件包和版本。然后使用aptitute对所列软件包进行降级:
aptitute install [paste output here]
我希望这对于其他人也可以节省时间。
我相信不是,除了采取相关的文件系统的完整备份(那些包含/
,/bin
,/lib
,/sbin
,/usr
,/var
,/etc
和/boot
(可能全部是关于文件系统)和您的引导记录),所以你可以滚机背之后。
/var
),并且所有相关的配置文件都已保存。然后,您可以通过明确告诉dpkg
安装那些版本来尝试强制回滚。如果您希望进行正常的升级,那么之后可能需要做一些工作,所以我不建议这样做。
有一个名为Nexenta的项目,该项目将OpenSolaris内核与Ubuntu用户空间结合在一起。它提供了集成Solaris的ZFS和Debian的apt的工具,以便为升级提供撤消按钮。参见此处:http : //www.nexenta.org/os/TransactionalZFSUpgrades
通常,您需要的是版本控制文件系统。Linux的Btrfs正在开发中。
使用Apt-Undo是一个可能的选项,但是只有在使用它来安装和卸载软件包时,它才有效。如果您已经以常规方式卸载了软件,那将无济于事。
http://www.ubuntugeek.com/apt-undo-a-simple-way-of-undoing-apt-actions.html http://lkubuntu.wordpress.com/2011/07/27/apt-undo-a简单的撤消适配动作的方法/
我已经成功完成了几次,但我不推荐这样做。这是我所做的(如果我没记错的话):
1)删除默认ubuntu信息库中未包含的所有非官方软件(可能不是必需的,但我建议您这样做,因为它们可能会妨碍您使用)。
2)将/etc/apt/sources.list(和sources.list.d / *)更改为以前的版本(注释所有非官方存储库)。
3)apt-get更新/ aptitude更新
4)使用aptitude降级核心软件包(如X11,库等)。它将开始发射很多损坏的程序包...因此,您需要解决每种情况(您需要知道如何适当地做到这一点)。降级的方法是转到描述面板并在底部安装版本(按+)。
5)重复#4,直到所有软件都属于您的目标版本(在aptitude中检查“版本”列)。
这些是为什么我不推荐此方法的原因:
我强烈建议您进行全新安装,并一点一点地移动您的配置。这也需要时间,但是最后您有了一个稳定的版本。
我这么做的原因主要是出于实验和绝望的结果。
如果您将操作系统安装在ZFS文件系统上(例如Linux上的ZFS ),则可以配置apt-get
为zfs snapshot
在安装或升级任何文件之前运行,这将立即备份您的文件系统。它可以与ZFS快照以外的备份机制一起使用,但是我将把测试留给其他人。
创建一个类似的文件
/etc/apt/apt.conf.d/71backup
有内容
// Tell `apt-get' to take a ZFS snapshot before installing or upgrading a
// set of packages:
DPkg::Pre-Install-Pkgs {"/sbin/zfs snapshot rpool/ROOT/debian@apt-get_$(date '+%Y-%m-%d-%H%M')";};
其中,rpool/ROOT/debian
应到您的操作系统安装在ZFS文件系统的名称来代替。您在首次安装操作系统时就给它起了名字,可以NAME
在命令的attribute下找到它。
# zfs list -t filesystem
NAME ...
...
rpool/ROOT/debian ...
...
在遵循一些随机互联网人士的配置建议之前,最好进行快照:
# zfs snapshot rpool/ROOT/debian@$(date '+%Y-%m-%d-%H%M%S')_test
# zfs list -t snapshot | grep rpool
...
rpool/ROOT/debian@2018-08-01-230001_test
在那里。如果error: fn_borked
很快发生,您可以使用以下命令将系统恢复到其幸福的当前状态:
# zfs rollback rpool/ROOT/debian@2018-08-01-230001_test
现在,通过安装两个可能在您的仓库中可用的微型游戏来进行尝试:
# apt-get install tanglet sudoku
...
# zfs list -t snapshot | grep apt\-get
rpool/ROOT/debian@apt-get_2018-08-02-033614
该快照包含安装两个游戏之前的文件系统。
# exit
$ sudoku
奶奶很开心,但您讨厌数独。
$ sudo -i
# zfs rollback rpool/ROOT/debian@apt-get_2018-08-02-033614
# exit
$ sudoku
-bash: /usr/games/sudoku: No such file or directory
$ tanglet
-bash: tanglet: command not found
拍摄了多个快照后,可以通过添加-r
标志来回滚到任何较早的快照。例如,在我们的例子中,尝试
# zfs -r rollback rpool/ROOT/debian@2018-08-01-230001_test
但是,请注意,这不仅会使您的文件系统恢复到rpool/ROOT/debian@2018-08-01-230001_test
拍摄时的状态,而且还会删除所有以后的快照,并且将无法删除。如果您跟随这篇文章,快照rpool/ROOT/debian@apt-get_2018-08-02-033614
现在将消失。
我apt-get upgrade
在Debian GNU / Linux上使用
# apt-get -t=oldstable install tanglet sudoku
...
# apt-get upgrade
...
# zfs list -t snapshot | grep apt\-get
有用。为该install
命令创建了一个快照,为该命令创建了另一个快照upgrade
。
警告:我今天第一次进行了测试,对apt的内部运作知之甚少。如果这会给您带来麻烦或带来我未曾考虑过的新想法的风险,请在下面对此进行评论。