【Maven学习】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目錄,查看里面的目錄結構
[root@kf1appsvr storage]# pwd /usr/local/sonatype-work/nexus/storage [root@kf1appsvr storage]# ll total 52 drwxr-xr-x 6 root root 4096 Dec 4 08:49 android-beta drwxr-xr-x 6 root root 4096 Dec 4 08:49 android-dev drwxr-xr-x 6 root root 4096 Dec 4 08:49 android-release drwxr-xr-x 6 root root 4096 Dec 4 08:49 android-snapshots drwxr-xr-x 10 root root 4096 Dec 4 08:49 android_public drwxr-xr-x 4 root root 4096 Dec 4 08:49 apache-snapshots drwxr-xr-x 30 root root 4096 Dec 4 08:49 central drwxr-xr-x 125 root root 4096 Nov 30 17:08 central-m1 drwxr-xr-x 6 root root 4096 Dec 4 08:49 public drwxr-xr-x 4 root root 4096 Dec 4 08:49 releases drwxr-xr-x 4 root root 4096 Dec 4 08:49 snapshots drwxr-xr-x 5 root root 4096 Dec 4 08:49 thirdparty 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私服倉庫之前制定的倉庫地址為
[root@localhost local]# cd nexus-2.12.1-01/ [root@localhost nexus-2.12.1-01]# ll 總用量 40 drwxr-xr-x 3 1001 1001 4096 12月 13 16:27 bin drwxr-xr-x 2 1001 1001 4096 12月 13 18:06 conf drwxr-xr-x 2 1001 1001 4096 12月 13 16:27 lib -rw-r--r-- 1 1001 1001 11006 3月 3 2016 LICENSE.txt drwxr-xr-x 2 1001 1001 4096 12月 13 18:08 logs drwxr-xr-x 4 1001 1001 4096 12月 13 16:27 nexus -rw-r--r-- 1 1001 1001 782 3月 3 2016 NOTICE.txt drwxr-xr-x 5 1001 1001 4096 12月 13 18:08 tmp [root@localhost nexus-2.12.1-01]# pwd /usr/local/nexus-2.12.1-01 [root@localhost nexus-2.12.1-01]# cat conf/nexus.properties # # Sonatype Nexus (TM) Open Source Version # Copyright (c) 2008-present Sonatype, Inc. # All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions. # # This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0, # which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html. # # Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks # of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the # Eclipse Foundation. All other trademarks are the property of their respective owners. ## Sonatype Nexus # ============== # This is the most basic configuration of Nexus.# Jetty section application-port=8081 application-host=0.0.0.0 nexus-webapp=${bundleBasedir}/nexus nexus-webapp-context-path=/nexus# Nexus section nexus-work=${bundleBasedir}/../sonatype-work/nexus runtime=${bundleBasedir}/nexus/WEB-INF [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修改后的配置文件如下所示
# # Sonatype Nexus (TM) Open Source Version # Copyright (c) 2008-present Sonatype, Inc. # All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions. # # This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0, # which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html. # # Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks # of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the # Eclipse Foundation. All other trademarks are the property of their respective owners. ## Sonatype Nexus # ============== # This is the most basic configuration of Nexus.# Jetty section application-port=8081 application-host=0.0.0.0 nexus-webapp=${bundleBasedir}/nexus nexus-webapp-context-path=/nexus# Nexus section #nexus-work=${bundleBasedir}/../sonatype-work/nexus #新的地址為 nexus-work=/data2/sonatype-work/nexus runtime=${bundleBasedir}/nexus/WEB-INF五、重啟Nexus
使用 /etc/init.d/nexus2 restart 命令 重啟Nexus服務
[root@localhost nexus]# /etc/init.d/nexus2 Usage: /etc/init.d/nexus2 { console | start | stop | restart | status | dump } [root@localhost nexus]# /etc/init.d/nexus2 restart **************************************** WARNING - NOT RECOMMENDED TO RUN AS ROOT **************************************** Stopping Nexus OSS... Stopped Nexus OSS. Starting Nexus OSS... Started Nexus OSS. [root@localhost nexus]#重啟完后,刷新瀏覽器查看新的Nexus服務器,如下所示
對比下,老的Nexus服務器
除了IP地址不一樣之外,其他的都一樣,遷移成功!
測試了下之前在博客 【我的Android進階之旅】快速創建和根據不同的版本類型(Dev、Beta、Release)發布Android 開發庫到Maven私服 中寫的Gradle腳本上傳到新的Nexus服務器也是正常的!
參考鏈接
- http://blog.csdn.net/ouyang_peng/article/details/78793038
- http://blog.csdn.net/vbaspdelphi/article/details/52870530
- http://blog.csdn.net/kinglyjn/article/details/53585721
- http://blog.csdn.net/north_eagle/article/details/42428219
- http://blog.csdn.net/puregold1124/article/details/45690785
- http://blog.csdn.net/ouyang_peng/article/details/56872556
作者:歐陽鵬 歡迎轉載,與人分享是進步的源泉!
轉載請保留原文地址:http://blog.csdn.net/ouyang_peng/article/details/78796215
本文同步發表在阿里云棲:https://yq.aliyun.com/articles/283565?spm=5176.blogshare283565.0.0.31jPfx
如果覺得本文對您有所幫助,歡迎您掃碼下圖所示的支付寶和微信支付二維碼對本文進行隨意打賞。您的支持將鼓勵我繼續創作!
總結
以上是生活随笔為你收集整理的【Maven学习】Nexus OSS私服仓库的备份与迁移的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: POJ1741:Tree——题解+树分治
- 下一篇: iOS攻防——(四)class-dump