Sonatype is looking through the archives and re-posting popular articles for those new to Sonatype tools.
The first post in the series is by Sonatype software developer Juven Xu, on backing up Nexus.
Nexus is the industry leading repository manager that helps reduce build times and increase your control of open source artifacts by managing software artifacts required for development, deployment, and provisioning. Nexus greatly simplifies the maintenance of your own internal repositories and access to external repositories such as Maven Central. With Nexus you can completely control access to, and deployment of, every artifact in your organization from a single location.
If you are already using Nexus Repository, this article will teach you how to back up your repository manager. (If you don't use Nexus Repository, you can click here for more information).
To backup Nexus simply means to make a copy of your Nexus files for safekeeping. The copy should be stored on different hardware, other than the original one. For example, you might want to copy your Nexus settings in the sonatype-work/nexus/config folder to a removable hard disk.
It is important to backup your Nexus files because sometimes things fail. Hard disk might crash, files might be deleted by other programs, even ourselves might delete important files by mistake. With a backup, you will be protected from these frustrating events.
Nexus consists of two parts, one part is the runtime web application, which can always be downloaded from Sonatype site, the other part is the sonatype-work/ folder, which contains all the user data and configuration. So here our focus is the sonatype-work/ folder. If you are running the Nexus bundle, this folder is next to the nexus-webapp directory. If you are using Nexus war, this folder should be under the user home directory by default.
You can simply backup the whole sonatype-work/ directory if you are rich in disk space, but it's not necessary. Some of the files in the directory are very important, or even unreproduceable, while some of the files can be easily regenerated. Here is a full list of sub-folders, from the most important to least:
Now that you know what files to backup according to your situation, you need to know how to backup your files.
Take this example:
My Nexus is running on Ubuntu Linux, the path of sonatype-work directory is /home/juven/bin/sonatype-work/, I have a removable disk which is mounted at /media/disk/, I am using rsync to make backup:
$ rsync -a -delete -v ~/bin/sonatype-work /media/disk/
This command is equivalent to:
$ cp -a ~/bin/sonatype-work /media/disk/
except that it's more efficient if there are only a few differences.
So this command will backup the whole sonatype-work folder, what if I only want to backup some important the sub-folders?
Suppose I only want to backup these folders: /sonatype-work/nexus/storage/releases/, /sonatype-work/nexus/storage/thirdparty/, /sonatype-work/nexus/conf/, /sonatype-work/nexus/storage/logs/, and /sonatype-work/nexus/storage/timeline/, create a rsync includes list file like this:
+ /sonatype-work/nexus/storage/
+ /sonatype-work/nexus/storage/releases/
+ /sonatype-work/nexus/storage/thirdparty/
+ /sonatype-work/nexus/conf/
+ /sonatype-work/nexus/logs/
+ /sonatype-work/nexus/timeline/
- /sonatype-work/nexus/storage/*
- /sonatype-work/nexus/*
$ rsync -a -delete -v --include-from includes.list ~/bin/sonatype-work /media/disk/
If your backup disk is always connected to your machine and you don' t want to repeat the backup command manually, then schedule a task running the backup periodically.
On Linux, cron is a perfect tool for automating the backup task. In my case on Linux, with user name 'juven', edit file /etc/crontab, add a line like this:
0 0 * * 0 juven rsync -a -delete --include-from ~/bin/includes.list ~/bin/sonatype-work /media/disk/
This entry tells cron to run the rsync command as user juven, weekly.
And don't forget to restart the cron deamon:
$ sudo /etc/init.d/cron restart
And that's it! It should automatically perform the backup at the time you specified.