原文地址:我可以用 opatch 清理以前的补丁包吗
原文作者:Mike.Dietrich
你是否喜欢秘密?现在让我从一个对大多数人来说不是秘密的秘密开始,让它变得更加晦涩难懂。
当您使用 opatch 或 opatchauto 安装补丁时,很多文件将存储在隐藏目录中:
$ORACLE_HOME/.patch_storage $ORACLE_HOME/.opatchauto_storage
复制
为什么隐藏这些目录?我真的不知道。也许是为了表示“不要碰任何东西!不得擅闯!远离!私人财产”。但是像往常一样,当你试图隐藏某些东西时,你只会让它变得更有趣。
无论如何,当您仔细观察时,尤其是当您在我的环境中拥有某种补丁历史记录时,您可能会很快意识到:使用了很多空间。
就我而言,这些目录在我的环境中总共消耗了超过 10GB 的空间:
[CDB2] oracle@hol:/u01/app/oracle/product/19/.patch_storage $ ls 32218454_Jan_14_2021_16_24_38 32545013_Apr_16_2021_07_40_05 32904851_Jul_20_2021_09_21_24 33192694_Sep_14_2021_16_48_27 33192793_Oct_15_2021_07_09_52 33197296_Oct_4_2021_00_44_36 33515361_Jan_13_2022_06_14_07 33561310_Jan_5_2022_08_13_10 interim_inventory.txt LatestOPatchSession.properties NApply newdirs.txt record_inventory.txt 10017056
复制
不要清除它
补丁所有者给出的第一条规则:不要清除此目录。稍后可能需要回滚补丁。
我仍然从一些人那里知道,他们不时删除整个目录以释放空间。到目前为止,我还没有听说这会破坏未来的补丁。如果我在我的环境中这样做,我会确保始终保留最后两个子目录——以防万一。但是我没有很多一次性或合并补丁。
- 规则 1:
不要清除.patch_storage和 . opatchauto_storage。
opatch 工具清理
让我把这一章写得很短。
- 规则 2:
opatch util cleanup不会做你期望它做的事情。有时它做的比你想象的要多一点。
解决办法是什么?
很长一段时间以来,许多客户都在寻求解决方案。只需简单浏览一下错误数据库,就会发现相当数量的错误和增强请求针对或要求 opatch 进行适当的清理。
下面的内容看起来很有趣:
Enh 31138227 – $OH/.PATCH_STORAGE 保留 N-1 版本仅用于更好的空间消耗
我本来希望有这样的解决方案,因为我通常在我的 Linux 系统上这样做:
# package-cleanup --oldkernels --count=1
复制
它删除了我不再需要或不再使用的旧内核。
从上面的增强请求中,我了解到从版本 26 开始有一个新的 opatch 选项可用:
./opatch util archive -patches 123456,1122334 -archive_dir /dirx
复制
这里的第一个问题是 opatch 中通常的-help选项没有告诉你它。由于增强请求是非公开的,因此您无法查看详细信息。但秘密关键字是:opatch util archive -help
注解:
实际上,我从功能所有者那里了解到,帮助没有向您显示帮助更高级别的命令选项的原因很简单——该功能还没有“上线”。由于我是通过我提交的一个错误了解它的,所以我尝试了它并且不知道它尚未公开。不过,它工作正常。
$ ./opatch util archive -help Oracle Interim Patch Installer version 12.2.0.1.28 Copyright (c) 2022, Oracle Corporation. All rights reserved. DESCRIPTION This operation helps to archive the patches stored under ORACLE_HOME/.patch_storage to custom storage location. NOTE: Patch directories in .patch_storage will be used during rollback operation. SYNTAX opatch util archive [-patches <List of Patch ids with comma separated>] [-archive_dir <path to store the archive files>] OPTIONS -patches A comma separated list of patches to be given for archive. -archive_dir Specify custom storage path to store the patches which are going to be archived. NOTE: All options are mandatory. RECOMMENDATION : To archive patches, opatch recommends the following 1. Archiving inactive patches : Run the following command to get inactive patches : "OPatch/opatch lsinv -inactive" Example opatch util archive -patches 123456,1122334 -archive_dir /dir1/dir2/ OPatch succeeded.
复制
所以这是新命令:opatch util archive -patches … -archive_dir …
不要对命令语法中的括号感到困惑。所有选项都是强制性的,而不是可选的。
这是解决千兆字节旧补丁内容浪费硬盘空间问题的承诺。让我们看看这是否也解决了您的问题。
哪些补丁目录是候选的?
当您搜索非活动房屋时,此 opatch 命令最有帮助,但输出很长:
$ ./opatch lsinv -inactive
复制
它会告诉您不活动的补丁号。这些是您要传递给下面的存档命令的那些。
opatch 实用程序存档
正如您之前所读到的,即使我之前自己非法清理过,我的机器上仍然消耗了超过 10GB 的空间。
尽管如此,归档命令仍会进行空间检查(请参阅下面的What if …)
$ ./opatch util archive -patches 32218454,32545013,32904851,33192694,33192793,33197296,33515361,33561310 -archive_dir /media/sf_TEMP/ Oracle Interim Patch Installer version 12.2.0.1.28 Copyright (c) 2022, Oracle Corporation. All rights reserved. Oracle Home : /u01/app/oracle/product/19 Central Inventory : /u01/app/oraInventory from : /u01/app/oracle/product/19/oraInst.loc OPatch version : 12.2.0.1.28 OUI version : 12.2.0.7.0 Log file location : /u01/app/oracle/product/19/cfgtoollogs/opatch/opatch2022-01-20_14-08-15PM_1.log Invoking utility "archive" Archiving Patch - 33515361 .... Sucessfully archived patch - 33515361 in /media/sf_TEMP/33515361_Jan_13_2022_06_14_07.zip Archiving Patch - 32545013 .... Sucessfully archived patch - 32545013 in /media/sf_TEMP/32545013_Apr_16_2021_07_40_05.zip Archiving Patch - 32904851 .... Sucessfully archived patch - 32904851 in /media/sf_TEMP/32904851_Jul_20_2021_09_21_24.zip Archiving Patch - 33197296 .... Sucessfully archived patch - 33197296 in /media/sf_TEMP/33197296_Oct_4_2021_00_44_36.zip Archiving Patch - 33192793 .... Sucessfully archived patch - 33192793 in /media/sf_TEMP/33192793_Oct_15_2021_07_09_52.zip Archiving Patch - 33192694 .... Sucessfully archived patch - 33192694 in /media/sf_TEMP/33192694_Sep_14_2021_16_48_27.zip Archiving Patch - 33561310 .... Sucessfully archived patch - 33561310 in /media/sf_TEMP/33561310_Jan_5_2022_08_13_10.zip Archiving Patch - 32218454 .... Sucessfully archived patch - 32218454 in /media/sf_TEMP/32218454_Jan_14_2021_16_24_38.zip Succesfully verified the created archive. Deleting the original patch from - /u01/app/oracle/product/19/.patch_storage/33515361_Jan_13_2022_06_14_07 Succesfully verified the created archive. Deleting the original patch from - /u01/app/oracle/product/19/.patch_storage/32545013_Apr_16_2021_07_40_05 Succesfully verified the created archive. Deleting the original patch from - /u01/app/oracle/product/19/.patch_storage/32904851_Jul_20_2021_09_21_24 Succesfully verified the created archive. Deleting the original patch from - /u01/app/oracle/product/19/.patch_storage/33197296_Oct_4_2021_00_44_36 Succesfully verified the created archive. Deleting the original patch from - /u01/app/oracle/product/19/.patch_storage/33192793_Oct_15_2021_07_09_52 Succesfully verified the created archive. Deleting the original patch from - /u01/app/oracle/product/19/.patch_storage/33192694_Sep_14_2021_16_48_27 Succesfully verified the created archive. Deleting the original patch from - /u01/app/oracle/product/19/.patch_storage/33561310_Jan_5_2022_08_13_10 Succesfully verified the created archive. Deleting the original patch from - /u01/app/oracle/product/19/.patch_storage/32218454_Jan_14_2021_16_24_38 Patch archive operation completed successfully. OPatch succeeded.
复制
如果 …
当然,使用 opatch 总是有很多有趣的 opatch 错误消息。
我的第一次尝试失败了:
$ ./opatch util archive -patches 32218454,32545013,32904851,33192694,33192793,33197296,33515361,33561310 -archive_dir /home/oracle/patch_storage Oracle Interim Patch Installer version 12.2.0.1.28 Copyright (c) 2022, Oracle Corporation. All rights reserved. Oracle Home : /u01/app/oracle/product/19 Central Inventory : /u01/app/oraInventory from : /u01/app/oracle/product/19/oraInst.loc OPatch version : 12.2.0.1.28 OUI version : 12.2.0.7.0 Log file location : /u01/app/oracle/product/19/cfgtoollogs/opatch/opatch2022-01-20_11-48-35AM_1.log Invoking utility "archive" Patch archive operation failed. UtilSession failed to Archive the patches UtilSession failed: Patch archive operation failed. OPatch failed with error code 73
复制
为什么失败了?我需要检查日志文件以找出:
[Jan 20, 2022 11:48:37 AM] [INFO] Archive directory: /home/oracle/patch_storage has required permission to archive the patches [Jan 20, 2022 11:48:37 AM] [INFO] Space for patch :: /u01/app/oracle/product/19/.patch_storage/32218454_Jan_14_2021_16_24_38 :: 1715352980 [Jan 20, 2022 11:48:37 AM] [INFO] Space for patch :: /u01/app/oracle/product/19/.patch_storage/32545013_Apr_16_2021_07_40_05 :: 1974092970 [Jan 20, 2022 11:48:37 AM] [INFO] Space for patch :: /u01/app/oracle/product/19/.patch_storage/32904851_Jul_20_2021_09_21_24 :: 1927088358 [Jan 20, 2022 11:48:38 AM] [INFO] Space for patch :: /u01/app/oracle/product/19/.patch_storage/33192793_Oct_15_2021_07_09_52 :: 1818503734 [Jan 20, 2022 11:48:38 AM] [INFO] Space for patch :: /u01/app/oracle/product/19/.patch_storage/33192694_Sep_14_2021_16_48_27 :: 444972030 [Jan 20, 2022 11:48:38 AM] [INFO] Space for patch :: /u01/app/oracle/product/19/.patch_storage/33197296_Oct_4_2021_00_44_36 :: 126355388 [Jan 20, 2022 11:48:38 AM] [INFO] Space for patch :: /u01/app/oracle/product/19/.patch_storage/33515361_Jan_13_2022_06_14_07 :: 1750455909 [Jan 20, 2022 11:48:38 AM] [INFO] Space for patch :: /u01/app/oracle/product/19/.patch_storage/33561310_Jan_5_2022_08_13_10 :: 452566990 [Jan 20, 2022 11:48:38 AM] [INFO] Archive directory: /home/oracle/patch_storage needs 10209388359 bytes. [Jan 20, 2022 11:48:38 AM] [SEVERE] No space to archive given patches in /home/oracle/patch_storage [Jan 20, 2022 11:48:38 AM] [INFO] Patch archive operation failed. [Jan 20, 2022 11:48:38 AM] [SEVERE] Patch archive operation failed. [Jan 20, 2022 11:48:38 AM] [INFO] UtilSession failed to Archive the patches [Jan 20, 2022 11:48:38 AM] [SEVERE] UtilSession failed to Archive the patches [Jan 20, 2022 11:48:38 AM] [SEVERE] OUI-67073:UtilSession failed: Patch archive operation failed. [Jan 20, 2022 11:48:38 AM] [INFO] Finishing UtilSession at Thu Jan 20 11:48:38 CET 2022 [Jan 20, 2022 11:48:38 AM] [INFO] Stack Description: java.lang.RuntimeException: Patch archive operation failed. at oracle.opatch.opatchutil.OUSession.archive(OUSession.java:3491) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at oracle.opatch.UtilSession.process(UtilSession.java:355) at oracle.opatch.OPatchSession.process(OPatchSession.java:2660) at oracle.opatch.OPatch.process(OPatch.java:870) at oracle.opatch.OPatch.main(OPatch.java:927) Caused by: java.lang.RuntimeException: Patch archive operation failed. ... 9 more
复制
你觉得这有点难读吗?我同意——我做了一个快速翻译,因为 190423787 的大小不容易使用。我也删除了一些输出。现在这工作得更好:
Archive directory: /home/oracle/patch_storage has required permission to archive the patches 32218454_Jan_14_2021_16_24_38 :: 1.715 GB 32545013_Apr_16_2021_07_40_05 :: 1.974 GB 32904851_Jul_20_2021_09_21_24 :: 1.927 GB 33192793_Oct_15_2021_07_09_52 :: 1.818 GB 33192694_Sep_14_2021_16_48_27 :: 0.444 GB 33197296_Oct_4_2021_00_44_36 :: 0.126 GB 32515361_Jan_13_2022_06_14_07 :: 1.750 GB 33561310_Jan_5_2022_08_13_10 :: 0.452 GB Archive directory: /home/oracle/patch_storage needs 10.209 GB. No space to archive given patches in /home/oracle/patch_storage
复制
计算采用每个补丁目录的当前大小(此处介于 444 MB 和 1.9 GB 之间,将其相加,计算出大约 10 GB 的大小 - 并说:“嘿,迈克,您的设备上没有足够的空间再存储 10 GB “。
所以我把文件放在我的主机系统的磁盘上,知道我至少有 80GB 的可用空间。这是 opatch 完成其职责后的结果:
688M Jan 20 14:10 33515361_Jan_13_2022_06_14_07.zip 948M Jan 20 14:12 32545013_Apr_16_2021_07_40_05.zip 824M Jan 20 14:13 32904851_Jul_20_2021_09_21_24.zip 119M Jan 20 14:13 33197296_Oct_4_2021_00_44_36.zip 717M Jan 20 14:15 33192793_Oct_15_2021_07_09_52.zip 118M Jan 20 14:15 33192694_Sep_14_2021_16_48_27.zip 120M Jan 20 14:15 33561310_Jan_5_2022_08_13_10.zip 725M Jan 20 14:17 32218454_Jan_14_2021_16_24_38.zip
复制
总共使用了 4.26 GB。这意味着消耗的空间不到 50%。
-
学习 1:
空间使用假设是完全错误的,并且使用当前大小而不是至少一个假设。 -
学习 2:
opatch util archive命令对每个补丁的子目录进行简单的压缩。
这让我想到了神奇的最后一个问题。
opatch util 存档会释放 .patch_storage 中的空间吗?
既然您已经看到上面的命令输出,您可能不再好奇了。
它进行清理。之后将删除每个要归档的补丁子目录。这就是我的.patch_storage目录之后的样子:
$ ls -lhrt total 160K -rw-r--r--. 1 oracle dba 24K Jan 19 21:39 newdirs.txt drwxr-xr-x. 16 oracle dba 4.0K Jan 19 22:12 NApply -rw-r--r--. 1 oracle dba 64K Jan 19 22:12 record_inventory.txt -rw-r--r--. 1 oracle dba 64K Jan 19 22:12 interim_inventory.txt -rw-r--r--. 1 oracle dba 92 Jan 19 22:12 LatestOPatchSession.properties
复制
所有子目录都消失了。它现在只累积了 160K。
我想我可以处理这个。
如果你想回滚补丁会发生什么?
我很高兴在删除我将它们存档到的主机环境中的所有补丁之前,我也尝试了这一点:
$ ./opatch rollback -id 33516412 Oracle Interim Patch Installer version 12.2.0.1.28 Copyright (c) 2022, Oracle Corporation. All rights reserved. Oracle Home : /u01/app/oracle/product/21 Central Inventory : /u01/app/oraInventory from : /u01/app/oracle/product/21/oraInst.loc OPatch version : 12.2.0.1.28 OUI version : 12.2.0.9.0 Log file location : /u01/app/oracle/product/21/cfgtoollogs/opatch/opatch2022-01-20_15-38-47PM_1.log Patches will be rolled back in the following order: 33516412 Prerequisite check "CheckRollbackable" failed. Possible causes are: The patch can not be rolled back No read or write permission to ORACLE_HOME/.patch _storage The ORACLE_HOME/.patch_storage file may have been removed. The details are: *************************************************** Following patches are archived: 33516412 Please follow the instructions below to unarchive the patches before proceeding with current Opatch operation (as /u01/app/oracle/product/21 owner). Step 1: /u01/app/oracle/product/21/OPatch/opatch util unarchive -patches 33516412 Step 2 : Resume/Rerun current Opatch operation: /u01/app/oracle/product/21/OPatch/opatch rollback -id 33516412 -invPtrLoc /u01/app/oracle/product/21/oraInst.loc *************************************************** UtilSession failed: Prerequisite check "CheckRollbackable" failed. Log file location: /u01/app/oracle/product/21/cfgtoollogs/opatch/opatch2022-01-20_15-38-47PM_1.log OPatch failed with error code 73
复制
所以我需要先“取消归档”补丁。
让我试试这个:opatch util unarchive -patches 33516412
$ /u01/app/oracle/product/21/OPatch/opatch util unarchive -patches 33516412 Oracle Interim Patch Installer version 12.2.0.1.28 Copyright (c) 2022, Oracle Corporation. All rights reserved. Oracle Home : /u01/app/oracle/product/21 Central Inventory : /u01/app/oraInventory from : /u01/app/oracle/product/21/oraInst.loc OPatch version : 12.2.0.1.28 OUI version : 12.2.0.9.0 Log file location : /u01/app/oracle/product/21/cfgtoollogs/opatch/opatch2022-01-20_15-40-58PM_1.log Invoking utility "unarchive" Unarchive given patches for given OH Started : unarchiving the patch dirs to OH/.patch_storage User specified list :[33516412] Total Space Needed for Unarchive :1511356677 Unarchive successful :/u01/app/oracle/product/21/.patch_storage/33516412_Jan_13_2022_06_54_26 Unarchive session is complete To clean up archives from custom storage path,Run the following command :'/u01/app/oracle/product/21/OPatch/opatch util cleanuparchives' OPatch succeeded.
复制
之后我可以为这个练习完成我的捆绑补丁的回滚。
- 学习 3:
如果您曾经计划回滚补丁包,请将存档保存在您要求 opatch 将它们存档到的完全相同的位置。否则,您可能无法回滚捆绑包。
其他发现
除了您需要知道获取“帮助”信息的命令这一事实之外,这是我很快遇到的另一个陷阱:
不要在补丁号之间放置空格字符。
当你这样做时:
$ ./opatch util archive -patches 33197448, 33587128 -archive_dir /media/sf_TEMP Oracle Interim Patch Installer version 12.2.0.1.28 Copyright (c) 2022, Oracle Corporation. All rights reserved. Syntax Error... Unrecognized Option for util. Please use the option 'opatch util -help' to get correct syntax OPatch failed with error code 14
复制
您会看到 opatch 因其中一个神秘错误而失败。
修复方法是去掉补丁号和逗号之间的空格,如:
$ ./opatch util archive -patches 33197448,33587128 -archive_dir /media/sf_TEMP Oracle Interim Patch Installer version 12.2.0.1.28 Copyright (c) 2022, Oracle Corporation. All rights reserved. Oracle Home : /u01/app/oracle/product/12.2.0.1 Central Inventory : /u01/app/oraInventory from : /u01/app/oracle/product/12.2.0.1/oraInst.loc OPatch version : 12.2.0.1.28 OUI version : 12.2.0.1.4 Log file location : /u01/app/oracle/product/12.2.0.1/cfgtoollogs/opatch/opatch2022-01-20_15-21-41PM_1.log Invoking utility "archive" Archiving Patch - 33587128 .... Sucessfully archived patch - 33587128 in /media/sf_TEMP/33587128_Dec_27_2021_16_38_16.zip Archiving Patch - 33197448 .... Sucessfully archived patch - 33197448 in /media/sf_TEMP/33197448_Oct_4_2021_05_28_49.zip Succesfully verified the created archive. Deleting the original patch from - /u01/app/oracle/product/12.2.0.1/.patch_storage/33587128_Dec_27_2021_16_38_16 Succesfully verified the created archive. Deleting the original patch from - /u01/app/oracle/product/12.2.0.1/.patch_storage/33197448_Oct_4_2021_05_28_49 Patch archive operation completed successfully. OPatch succeeded.
复制
然后它工作。
-
学习 4:
不要在逗号分隔的补丁号列表中使用空格字符作为-patches -
学习 5:
新的opatch util archive命令释放了大量空间。不幸的是,没有自动性,仍然是非 n-1 解决方案。但是你们中的大多数人不会受到影响,因为你修补了新家,只是从一个家转到另一个家。
在我的测试中,我在 3 个 Oracle Home、12.2.0.1、19c 和 21c 中总共释放了大约 15GB。我仍然想要的是一个 n-1 选项,仅自动保留上一个补丁并清除旧补丁,因为我很少会跳回多个补丁包,如果有的话。此外,我还期望有一个“全部”开关,它可以清除每个补丁,而无需复制和粘贴单独的补丁号。
清理档案
最后——感谢向我指出这一点的斯蒂芬安德森——问题仍然存在:
你现在需要手动从磁盘中删除档案吗?
让我们看看,因为有另一个——或多或少没有记录的——命令。您可能已经在上面的输出中看到了这一点:
opatch util cleanuparchives
让我向您展示这是如何工作的:
$ $ORACLE_HOME/OPatch/opatch util cleanuparchives Oracle Interim Patch Installer version 12.2.0.1.28 Copyright (c) 2022, Oracle Corporation. All rights reserved. Oracle Home : /u01/app/oracle/product/19 Central Inventory : /u01/app/oraInventory from : /u01/app/oracle/product/19/oraInst.loc OPatch version : 12.2.0.1.28 OUI version : 12.2.0.7.0 Log file location : /u01/app/oracle/product/19/cfgtoollogs/opatch/opatch2022-01-21_12-27-56PM_1.log Invoking utility "cleanuparchives" Started : Util cleauparchives session Patch id :33515361 Patch id :32545013 Patch id :32904851 Patch id :33197296 Patch id :33192793 Patch id :33192694 Patch id :33561310 Patch id :32218454 Nothing to cleanup Cleanuparchives from secondary storage is successful. OPatch succeeded.
复制
现在知道 opatch 很长一段时间了,我想知道这个“ Nothing to cleanup ”消息,然后是“… is successful ”输出。发生了什么事?
首先,我检查了我的存档存储——所有文件都还在。
然后作为下一步,我尝试恢复一个物理上仍在磁盘上的档案,就像我之前所做的那样:
$ /u01/app/oracle/product/21/OPatch/opatch util unarchive -patches 33515361 Oracle Interim Patch Installer version 12.2.0.1.28 Copyright (c) 2022, Oracle Corporation. All rights reserved. Oracle Home : /u01/app/oracle/product/19 Central Inventory : /u01/app/oraInventory from : /u01/app/oracle/product/19/oraInst.loc OPatch version : 12.2.0.1.28 OUI version : 12.2.0.7.0 Log file location : /u01/app/oracle/product/19/cfgtoollogs/opatch/opatch2022-01-21_12-31-31PM_1.log Invoking utility "unarchive" Unarchive given patches for given OH Started : unarchiving the patch dirs to OH/.patch_storage User specified list :[33515361] Total Space Needed for Unarchive :1750455909 Unarchive successful :/u01/app/oracle/product/19/.patch_storage/33515361_Jan_13_2022_06_14_07 Unarchive session is complete To clean up archives from custom storage path,Run the following command :'/u01/app/oracle/product/19/OPatch/opatch util cleanuparchives' OPatch succeeded.
复制
所以基本上我不能告诉你“ cleanuparchives ”命令做了什么,或者它是否应该做任何事情。opatch 日志文件对我没有任何帮助。命令的帮助告诉我:
$ $ORACLE_HOME/OPatch/opatch util cleanuparchives -help Oracle Interim Patch Installer version 12.2.0.1.28 Copyright (c) 2022, Oracle Corporation. All rights reserved. DESCRIPTION This operation helps to cleanup the archived files from custom storage location. NOTE: This will not cleanup any other directories/files in the system. This will only cleanup the archives generated as part of util archive operation. SYNTAX opatch util cleanuparchives
复制
我可以确认它没有做它应该做的事情。