Apache Archiva-specific information

From The Open Source Backup Wiki (Amanda, MySQL Backup, BackupPC)
Jump to navigationJump to search

Apache Archiva uses two databases: users and artifacts. The only database that must be backed up is the database with users, because Apache Archiva can regenerate the database with artifacts based on the artifacts found in the repositories. The example script below does backup the database with artifacts, but you can choose not to if you want.

Using the default Derby database

The database documentation of Apache Archiva says that you can simply copy the directory and files of the Derby databases to make a backup (see section Backing up the database at the bottom). But according to the backup and restore documentation of Apache Derby this will not work. Doing so may result in an inconsistent database in the backup.

You must either:

  • Make an offline backup:
    • Shutdown the database so you can perform a backup using native tools, and then start the database again.
  • Make an online backup:
    • Instruct Derby to write a consistent copy of the running database somewhere, and then use native tools to back up the copy.
    • Ask Derby to freeze the running database, then use native tools to back up the database files, and then ask Derby to unfreeze the database.

Only offline backups of the Apache Archiva databases are discussed here.

Offline backup

To make an offline backup of the databases the following procedure must be followed:

  • Stop Apache Archiva.
  • Copy the database files.
  • Start Apache Archiva.

Even with large databases Apache Archiva should only be offline for less than a minute.

Here is an example Linux shell script that keeps a copy of the database of the last two days. The script must be run as root so Apache Archiva can be stopped and started. In this script the database copies are stored in /backups/Archiva, and this directory must be created first:

mkdir /backups
chown root:backup /backups
chmod u=rwx,g=rxs,o= /backups
umask 0027
mkdir /backups/Archiva

Using cron, run the script every day before Amanda starts a backup. Also take the time at which automated builds run into consideration:

0 0 * * * /root/backupArchiva

Adapt this script to match your environment:

#!/bin/sh
# Prevent other users from accessing the copies
umask 0037

# Remove copies from the day before yesterday
/bin/rm /backups/Archiva/archiva-`date --date="2 days ago" +%F`.zip 2>/dev/null
/bin/rm /backups/Archiva/users-`date --date="2 days ago" +%F`.zip 2>/dev/null

/etc/init.d/archiva stop

cd /home/archiva/apache-archiva-1.3.2/data/databases/archiva
/usr/bin/zip -r /backups/Archiva/archiva-`date +%F`.zip * >/dev/null

cd /home/archiva/apache-archiva-1.3.2/data/databases/users
/usr/bin/zip -r /backups/Archiva/users-`date +%F`.zip * >/dev/null

/etc/init.d/archiva start

You can now add the databases directory of Apache Archiva to the exclude list: /home/archiva/apache-archiva-1.3.2/data/databases

Using another database

If you do not use the Derby databases, you can use the backup procedure of the database that you use instead.