Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Nexus OSS Private Repository Backup and Migration Guide

Tech May 7 4

Background

After setting up a new Nexus OSS private repository in our data center, we noticed that the existing office-based repository contains significantly more content than the new one. This document outlines the complete process of backing up and migrating the old Nexus server to the new infrastructure.

1. Backup of the Existing Nexus Repository

The migration process involves three key directories that need to be packaged, transferred, and then activated on the new server.

Name Directory Name Key Configuration Files
Nexus main directory nexus-2.6.4-02 conf/nexus.properties contains the sonatype-work path
Sonatype-work directory sonatype-work nexus/conf/nexus.xml contains storage configuration
Storage directory storage Contains various application JAR files and artifacts

Backup Process

First, we need to identify the relevant directories on the existing Nexus server:

The Nexus main directory is located at: /usr/local/nexus-2.12.1-01

The configuration file at /usr/local/nexus-2.12.1-01/config/nexus.properties specifies the sonatype-work location.

Next, we navigate to the storage directory to examine its structure:

[root@old-server storage]# pwd
/usr/local/sonatype-work/nexus/storage
[root@old-server storage]# ls -la
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

This directory structure corresponds to the repositories visible in the Nexus management interface.

Based on this analysis, we need to back up both the nexus main directory and the sonatype-work directory. However, since Java paths and other configurations might differ between servers, we'll only back up the sonatype-work directory, which contains all the repository artifacts.

The sonatype-work directory location is specified in the nexus/conf/nexus.properties configuration file.

We use the tar command to create a compressed backup of the sonatype-work directory:

[root@old-server local]# tar -zcvf repository-backup-2023-05-15.tar.gz ./sonatype-work/

The backup process may take considerable time due to the large number of files accumulated over two years.

Upon completion, the backup file repository-backup-2023-05-15.tar.gz is created, occupying approximately 2.6 GB of space.

2. Transferring the Backup to the New Nexus Server

Having compressed the sonatype-work directory into repository-backup-2023-05-15.tar.gz, we now need to transfer this file to the new Nexus server.

We use the scp command for this transfer operation:

scp username@old-server-ip:/usr/local/repository-backup-2023-05-15.tar.gz /usr/local/

Parameters that might be useful:

  • -v: Displays progress information, useful for troubleshooting connection, authentication, or configuration issues.
  • -C: Enables compression.
  • -P: Specifies a port. Note that -p is already used by rcp.
  • -4: Forces the use of IPv4 addresses.
  • -6: Forces the use of IPv6 addresses.

For example, to copy the backup file from the remote server to the /usr/local directory on the new server:

scp root@old-server-ip:/usr/local/repository-backup-2023-05-15.tar.gz /usr/local/

After executing the command, you'll need to confirm the connection by typing 'yes' and then providing the password for the old server.

If the password is correct, the backup file will be copied to the new server. However, in our case, the transfer was interrupted due to insufficient disk space on the root filesystem (/). We resolved this by transferring the file to /data2, which had adequate space:

scp root@old-server-ip:/usr/local/repository-backup-2023-05-15.tar.gz /data2/

After successful transfer, we verify the file size to confirm完整性:

[root@new-server data2]# ls -lh repository-backup-2023-05-15.tar.gz
-rw-r--r-- 1 root root 2.6G May 15 10:30 repository-backup-2023-05-15.tar.gz

3. Extracting the Backup File

Due to insufficient space in the root directory (/), we extract the compressed backup to the /data2 directory:

tar -zxvf repository-backup-2023-05-15.tar.gz

After extraction, a sonatype-work directory is created in /data2.

4. Restoring the Repository

Our new Nexus server is configured with the following directory structure:

[root@new-server local]# cd nexus-2.12.1-01/
[root@new-server nexus-2.12.1-01]# ls -la
total 40
drwxr-xr-x 3 1001 1001 4096 May 13 16:27 bin
drwxr-xr-x 2 1001 1001 4096 May 13 18:06 conf
drwxr-xr-x 2 1001 1001 4096 May 13 16:27 lib
-rw-r--r-- 1 1001 1001 11006 Mar 3 2016 LICENSE.txt
drwxr-xr-x 2 1001 1001 4096 May 13 18:08 logs
drwxr-xr-x 4 1001 1001 4096 May 13 16:27 nexus
-rw-r--r-- 1 1001 1001 782 Mar 3 2016 NOTICE.txt
drwxr-xr-x 5 1001 1001 4096 May 13 18:08 tmp
[root@new-server nexus-2.12.1-01]# pwd
/usr/local/nexus-2.12.1-01
[root@new-server 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

Since we extracted the backup to /data2, we need to modify the nexus/conf/nexus.properties file to point to the new location:

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

The modified configuration should look like this:

#
# 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
# Updated location
nexus-work=/data2/sonatype-work/nexus
runtime=${bundleBasedir}/nexus/WEB-INF

5. Restarting Nexus

Use the following command to restart the Nexus service:

[root@new-server 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.

After restarting, refresh the browser to view the new Nexus server. The repositories should now match those from the old server, except for the IP address differences, indicating a successful migration.

To verify the migration, test uploading artifacts using Gradle scripts to ensure the new Nexus server functions correctly.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

SBUS Signal Analysis and Communication Implementation Using STM32 with Fus Remote Controller

Overview In a recent project, I utilized the SBUS protocol with the Fus remote controller to control a vehicle's basic operations, including movement, lights, and mode switching. This article is aimed...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.