背景

在上一篇博客 【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服务器也是正常的!

Nexus OSS私服仓库的备份与迁移的更多相关文章

  1. 【Maven学习】Nexus OSS私服仓库的备份与迁移

    背景 在上一篇博客 [Maven学习]Nexus OSS私服仓库的安装和配置 中,我们已经在机房搭建好了新的Nexus OSS私服仓库.下面是两个版本的Nexus OSS私服仓库的对比图. 老的Nex ...

  2. 【Maven学习】Nexus OSS私服仓库的安装和配置

    背景 公司的代码依赖是通过Maven进行管理的,而Maven的私库我们使用的是Nexus,目前使用的版本是Nexus Repository Manager OSS 2.12.1. 但是由于之前我们搭建 ...

  3. 使用 Nexus 搭建私服仓库时我犯的一个小错误

    私服搭建好,啥都配置好了,纳闷的是 Repositories 中的 group 为何总是空值?我还反反复复删了又重建,结果还是一样,不经意间再看 Configuration 选项卡的内容,发现左右两个 ...

  4. Maven与Nexus OSS

    Maven 是一个项目管理和构建自动化工具,是Apache Fundation下的一个Java项目.常用于Java项目中依赖管理 下载直接去官网 安装Maven 已经编译的二进制包 直接解压到安装目录 ...

  5. nexus(Maven仓库私服)的安装、配置、使用和仓库迁移

    简介 Nexus下载:点击进入 Nexus 是Maven仓库管理器,如果你使用Maven,你可以从Maven中央仓库 下载所需要的构件(artifact),但这通常不是一个好的做法,你应该在本地架设一 ...

  6. 私服仓库 nexus 环境搭建(win10)

    1.1 简介: Nexus 是Maven仓库管理器,如果你使用Maven,你可以从Maven中央仓库 下载所需要的构件(artifact),但这通常不是一个好的做法,你应该在本地架设一个Maven仓库 ...

  7. 试用 Nexus OSS 3.0 的docker仓库 (二)

    试用 Nexus OSS 3.0 的docker仓库 (一) : http://www.cnblogs.com/wzy5223/p/5410990.html 三. 创建docker私有仓库,docke ...

  8. 试用 Nexus OSS 3.0 的docker仓库 (一)

    Nexus 3.0 可以创建三种docker仓库: 1. docker (proxy)      代理和缓存远程仓库 ,只能pull 2. docker (hosted)    托管仓库 ,私有仓库, ...

  9. 抗忙,,建个MAVEN的私服仓库-NEXUS

    公司最近需求越来越上轨道,MAVEN的私服仓库-NEXUS构架起来哟.. 参考文档URL: http://www.linuxidc.com/Linux/2011-07/39578p3.htm http ...

随机推荐

  1. 女性长期没有"恩爱",会出现这4个后果?提醒:频率最好能在这个数

    一直以来,很多人认为:男性性欲比女性强! 其实:因人而异! 但不管怎么说,“性”话题在如今社会中已经不再成为隐晦谈资. 越来越多的人,可以把此话题拿到桌面上各抒己见. 总归,“性”是我们探索自我的一种 ...

  2. 虚拟环境和pip相关的命令

    # 虚拟环境 mkvirtualenv # 创建虚拟环境 rmvirtualenv # 删除虚拟环境 workon # 进入虚拟环境.查看所有虚拟环境 deactivate # 退出虚拟环境 eg: ...

  3. ECharts堆叠柱状图label显示总和

    Echarts本身没提供现成的解决方案. option = { title: { text: '分类销量' }, legend: { y: "bottom", data: ['百货 ...

  4. Vue.js---指令与事件、语法糖

    指令与事件 指令(Directives)是Vue.js模板中最常用的一项功能,它带有前缀v-,指令的职责就是当其表达式的值改变时,相应地将某些行为应用到DOM上. v-if: 显示这段文本 当数据sh ...

  5. Easy2game使用

    每个独享IP服务器,开设3-5个高速接口IP,用户可自行选择当地连接速度快的接口接入服务器,服务器再为用户自动分配所绑定的独享IP连接至游戏服务器,可保证连接的稳定性,统一性 打开软件 添加程序 服务 ...

  6. Spark广播变量和累加器

    一.广播变量图解 二.代码 val conf = new SparkConf() conf.setMaster("local").setAppName("brocast& ...

  7. Java 虚拟机 - GC 垃圾回收机制分析

    Java 垃圾回收(Garbage Collection,GC) Java支持内存动态分配.垃圾自动回收,而 C++ 不支持.我想这可能也是 为什么 Java 脱胎于 C++ 的一个原因吧. GC 的 ...

  8. postgresql9.5编译安装体验

    实验环境: centos7.6 pgsql9.5 源码编译安装 实验目的: 体验源码编译安装pgsql 01.download https://ftp.postgresql.org/pub/sourc ...

  9. 服务器架构前面加了防火墙,Nginx如何获取客户端真实ip???

    在大部分实际业务场景中,网站访问请求并不是简单地从用户(访问者)的浏览器直达网站的源站服务器,中间可能经过所部署的CDN.高防IP.WAF等代理服务器.例如,网站可能采用这样的部署架构:用户 > ...

  10. Sql 语句中 IN 和 EXISTS 的区别

    IN 语句:只执行一次 确定给定的值是否与子查询或列表中的值相匹配.in在查询的时候,首先查询子查询的表,然后将内表和外表做一个笛卡尔积,然后按照条件进行筛选.所以相对内表比较小的时候,in的速度较快 ...