Nexus OSS私服倉庫的備份與遷移


背景

在上一篇博客 【Maven學習】Nexus OSS私服倉庫的安裝和配置 中,我們已經在機房搭建好了新的Nexus OSS私服倉庫。下面是兩個版本的Nexus OSS私服倉庫的對比圖。

老的Nexus OSS私服倉庫
這里寫圖片描述

新的Nexus OSS私服倉庫

這里寫圖片描述

明顯老的Nexus OSS私服倉庫的內容比新的Nexus OSS私服倉庫的內容多。因此我們現在的工作就是將辦公室上的老的Nexus服務器上的所有的數據遷移到機房的Nexus服務器。這一篇博客記錄下整個Nexus OSS私服倉庫的備份與遷移的過程。

一、老的Nexus OSS私服倉庫備份

遷移中會遇到三個文件夾 , 打包、拉走 啟動即可。

名稱 目錄名 重要配置文件
nexus主目錄 nexus-2.6.4-02 conf/nexus.properties里面有sonatype-work的地址
sonatype-work目錄 sonatype-work nexus/conf/nexus.xml里面有storage的地址
storage目錄 storage 里面主要是各種程序的jar包等

遷移流程如下

這里寫圖片描述

首先我們在老的Nexus OSS私服倉庫的這台Linux服務器上,查看相關的目錄信息。

這里寫圖片描述

如上圖所示,在老的Nexus OSS私服倉庫的這台Linux服務器上,

nexus主目錄的地址為:/usr/local/nexus-2.12.1-01

這里寫圖片描述

在 /usr/local/nexus-2.12.1-01/config/nexus.properties 文件中,指定了sonatype-work的地址

現在我們進入 /usr/local/sonatype-work/nexus/storage目錄,查看里面的目錄結構

  1. [root@kf1appsvr storage] # pwd
  2. /usr/ local/sonatype-work/nexus/storage
  3. [root@kf1appsvr storage] # ll
  4. total 52
  5. drwxr-xr- x 6 root root 4096 Dec 4 08:49 android-beta
  6. drwxr-xr- x 6 root root 4096 Dec 4 08:49 android-dev
  7. drwxr-xr- x 6 root root 4096 Dec 4 08:49 android-release
  8. drwxr-xr- x 6 root root 4096 Dec 4 08:49 android-snapshots
  9. drwxr-xr- x 10 root root 4096 Dec 4 08:49 android_public
  10. drwxr-xr- x 4 root root 4096 Dec 4 08:49 apache-snapshots
  11. drwxr-xr- x 30 root root 4096 Dec 4 08:49 central
  12. drwxr-xr- x 125 root root 4096 Nov 30 17:08 central-m1
  13. drwxr-xr- x 6 root root 4096 Dec 4 08:49 public
  14. drwxr-xr- x 4 root root 4096 Dec 4 08:49 releases
  15. drwxr-xr- x 4 root root 4096 Dec 4 08:49 snapshots
  16. drwxr-xr- x 5 root root 4096 Dec 4 08:49 thirdparty
  17. drwxr-xr- x 2 root root 4096 Jan 11 2017 xtc_devs

這里寫圖片描述

將此目錄結構和Nexus管理界面對比,可以一一對應,如下所示。
這里寫圖片描述

從上面分析來看,我們只需要將nexus主目錄和sonatype-work目錄都備份好即可。但是兩個Linux服務器的nexus配置的java路徑之類的可能不同,我就不備份nexus主目錄了。

我只備份sonatype-work目錄,Nexus的構件倉庫都保存在sonatype-work目錄中,該目錄的位置由nexus/conf/nexus.properties配置文件指定。

使用 tar命令將 sonatype-work目錄 打包壓縮為一個 tar.gz文件,命令如下所示

[root@kf1appsvr local]# tar -zcvf sonatype-work-2017-12-14.tar.gz ./sonatype-work/

備份中,整個備份過程比較緩慢,因為兩年傳上去的的文件和文件夾太多了。

這里寫圖片描述

打包完畢

這里寫圖片描述
生成了 sonatype-work-2017-12-14.tar.gz 文件,占用了2770940709 字節,差不多2.6G
這里寫代碼片

二、將老的Nexus OSS私服倉庫的備份文件復制到新的Nexus OSS私服倉庫

上一步我們將整個 sonatype-work 目錄打包成一個壓縮包 sonatype-work-2017-12-14.tar.gz,現在我們要將這個壓縮包復制到新的Nexus OSS私服倉庫的Linux服務器上。

我們是有 scp命令來進行復制操作,關於scp命令的操作可以參考之前的文章 git學習------> Gitlab如何進行備份恢復與遷移?

使用scp命令從遠程服務器copy文件或者目錄到本地

scp 用戶名 @IP 地址 : 文件名 1 遠程用戶名 @IP 地址 : 文件名 2

[用戶名 @IP 地址 :] 可以不輸入 , 可能需要輸入遠程用戶名所對應的密碼 .

可能有用的幾個參數 :

  • -v 和大多數 linux 命令中的 -v 意思一樣 , 用來顯示進度 . 可以用來查看連接 , 認證 , 或是配置錯誤 .
  • -C 使能壓縮選項 .
  • -P 選擇端口 . 注意 -p 已經被 rcp 使用 .
  • -4 強行使用 IPV4 地址 .
  • -6 強行使用 IPV6 地址 .

例如我使用如下命令,從遠程服務器copy剛才的備份文件sonatype-work-2017-12-14.tar.gz到了新服務器的/usr/local 目錄下

scp root@老的linux的ip地址:/usr/local/sonatype-work-2017-12-14.tar.gz /usr/local/

我們登錄到新的Nexus OSS私服倉庫那台linux服務器,然后執行上面的命令

這里寫圖片描述

敲了命令之后,需要我們確認是否connecting,我們敲一個yes,接着需要我們輸入老的Nexus OSS私服倉庫那台linux服務器的密碼,如下所示

這里寫圖片描述

敲完之后,如果密碼正確的話,則將剛才的備份文件copy到這台新的linux服務器。稍等一段時間之后則可以copy完畢,如下圖所示:

這里寫圖片描述

真心尷尬,根目錄 / 的磁盤空間用完了,導致復制過程終止,我們將這個復制到一半的文件刪除掉。

我發現 /data2 的磁盤空間很充裕,因此我將文件復制到 /data2目錄下,如下圖所示

這里寫圖片描述

復制完畢之后,查看 /data2 目錄,發現 復制過來的 sonatype-work-2017-12-14.tar.gz 文件也是 2770940709個字節,完整復制過來了。

這里寫圖片描述

三、解壓備份文件

因為 根目錄 / 下的磁盤空間不足,因此我們將剛才的壓縮包解壓到 /data2目錄下。如下所示:

tar -zxvf sonatype-work-2017-12-14.tar.gz

這里寫圖片描述

解壓過程

這里寫圖片描述

解壓好后,會生成一個 sonatype-work目錄。如下圖所示:

這里寫圖片描述

四、還原倉庫

因為我們新的Nexus OSS私服倉庫之前制定的倉庫地址為

  1. [root@localhost local]# cd nexus-2.12.1-01/
  2. [root@localhost nexus- 2.12.1-01]# ll
  3. 總用量 40
  4. drwxr-xr- x 3 1001 1001 4096 12月 13 16:27 bin
  5. drwxr-xr- x 2 1001 1001 4096 12月 13 18:06 conf
  6. drwxr-xr- x 2 1001 1001 4096 12月 13 16:27 lib
  7. -rw-r--r-- 1 1001 1001 11006 3月 3 2016 LICENSE.txt
  8. drwxr-xr- x 2 1001 1001 4096 12月 13 18:08 logs
  9. drwxr-xr- x 4 1001 1001 4096 12月 13 16:27 nexus
  10. -rw-r--r-- 1 1001 1001 782 3月 3 2016 NOTICE.txt
  11. drwxr-xr- x 5 1001 1001 4096 12月 13 18:08 tmp
  12. [root@localhost nexus- 2.12.1-01]# pwd
  13. /usr/ local/nexus-2.12.1-01
  14. [root@localhost nexus- 2.12.1-01]# cat conf/nexus.properties
  15. #
  16. # Sonatype Nexus (TM) Open Source Version
  17. # Copyright (c) 2008-present Sonatype, Inc.
  18. # All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
  19. #
  20. # This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
  21. # which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
  22. #
  23. # Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
  24. # of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
  25. # Eclipse Foundation. All other trademarks are the property of their respective owners.
  26. #
  27.  
  28. # Sonatype Nexus
  29. # ==============
  30. # This is the most basic configuration of Nexus.
  31.  
  32. # Jetty section
  33. application-port= 8081
  34. application-host= 0.0.0.0
  35. nexus-webapp=${bundleBasedir}/nexus
  36. nexus-webapp-context-path= /nexus
  37.  
  38. # Nexus section
  39. nexus-work=${bundleBasedir}/../sonatype-work/nexus
  40. runtime=${bundleBasedir}/nexus/WEB-INF
  41. [root@localhost nexus- 2.12.1-01]#

這里寫圖片描述

現在我們將老的Nexus OSS私服倉庫的備份倉庫 解壓到了 /data2目錄下,因此我們需要修改nexus/conf/nexus.properties配置文件,重新指定倉庫的目錄為 /data2/sonatype-work/nexus

這里寫圖片描述

我們修改 /usr/local/nexus-2.12.1-01/conf/nexus.properties 文件

[root@localhost nexus]# vim /usr/local/nexus-2.12.1-01/conf/nexus.properties

修改后的配置文件如下所示

  1. #
  2. # Sonatype Nexus (TM) Open Source Version
  3. # Copyright (c) 2008-present Sonatype, Inc.
  4. # All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
  5. #
  6. # This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
  7. # which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
  8. #
  9. # Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
  10. # of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
  11. # Eclipse Foundation. All other trademarks are the property of their respective owners.
  12. #
  13.  
  14. # Sonatype Nexus
  15. # ==============
  16. # This is the most basic configuration of Nexus.
  17.  
  18. # Jetty section
  19. application-port=8081
  20. application-host=0.0.0.0
  21. nexus-webapp=${bundleBasedir}/nexus
  22. nexus-webapp-context-path=/nexus
  23.  
  24. # Nexus section
  25. #nexus-work=${bundleBasedir}/../sonatype-work/nexus
  26. #新的地址為
  27. nexus-work=/data2/sonatype-work/nexus
  28. runtime=${bundleBasedir}/nexus/WEB-INF

這里寫圖片描述

五、重啟Nexus

使用 /etc/init.d/nexus2 restart 命令 重啟Nexus服務

  1. [root@localhost nexus] # /etc/init.d/nexus2
  2. Usage: /etc/init.d/nexus2 { console | start | stop | restart | status | dump }
  3. [root@localhost nexus] # /etc/init.d/nexus2 restart
  4. ****************************************
  5. WARNING - NOT RECOMMENDED TO RUN AS ROOT
  6. ****************************************
  7. Stopping Nexus OSS...
  8. Stopped Nexus OSS.
  9. Starting Nexus OSS...
  10. Started Nexus OSS.
  11. [root@localhost nexus] #

這里寫圖片描述

重啟完后,刷新瀏覽器查看新的Nexus服務器,如下所示

這里寫圖片描述

對比下,老的Nexus服務器

這里寫圖片描述

除了IP地址不一樣之外,其他的都一樣,遷移成功!

測試了下之前在博客 【我的Android進階之旅】快速創建和根據不同的版本類型(Dev、Beta、Release)發布Android 開發庫到Maven私服 中寫的Gradle腳本上傳到新的Nexus服務器也是正常的!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM