Backup and Restore on SonarW

SonarW supports incremental backups. The backup program can run on any Linux host - possibly the same host where SonarW resides but more likely a separate host. Full or incremental backups can be made from a running SonarW host to a local directory (local to where the backup program is running). All the databases found on the running SonarW host will be synchronized and will result in a full or incremental backup, which can later be restored to a SonarW instance.

The backup script requires the following parameters in the backup.conf file:

  • backup_dir: Full path of a local directory where the backups will be created.
  • sonar_client_uri: URI used to create a client connection to SonarW, e.g. mongodb://username:password@
  • server_host_uri: URI of the server host, e.g. qa@

Installation and setup

  1. Download and install the SonarBackup package; refer to the SonarW documentation for prerequisites and OS specific details:
  2. Create a backup directory; make sure that sonarw user has full privileges to that directory, for example:

    sudo mkdir /sonarw-backup
    sudo chown -R sonarw.sonar /sonarw-backup
  3. Change to sonarw user and cd to its home directory (typically /var/lib/sonarw), for example:

    sudo su sonarw``
    cd ~
  4. Create an ssh folder and generate ssh key pairs (skip if already exists), for example:

    mkdir ~sonarw/.ssh
    cd ~sonarw/.ssh
    ssh-keygen -N ""
  5. Copy ‘~sonarw/.ssh/’ from the backup machine to ~/sonarw/.ssh/authorized_keys to the SonarW node, for example:

    scp ~sonarw/.ssh/ <your-user>@<SonarW-node-ip>:/tmp/
  6. On the SonaW node, add the content of the copied file to ~sonarw/.ssh/authorized_keys, for example:

    sudo su sonarw
    cd ~sonarw/.ssh (create .ssh folder if doesn't exist).
    cat /tmp/ >> authorized_keys
  7. Make sure that ~sonarw/.ssh is owned by sonarw.sonar and that ~sonarw/.ssh/authorized_keys permissions are 600, for example:

    sudo chown sonarw.sonar ~sonarw/.ssh/authorized_keys
    sudo chmod 600 ~sonarw/.ssh/authorized_keys
  8. Remove the temporary copy of

    rm /tmp/
  9. Set the input parameters described above in the backup.conf file.


Run the backup script to create a full or incremental backup as follows:: (–inc | –full) [–verbose –debug –config=<full path to config file>] -h | –help

-h –help help screen –inc make incremental backup –full make full backup –verbose add outputs to stdout –debug can print optional debug messages to log file –config=<path> full path to config file to use for backup. default is /etc/sonar/backup.conf


Verbose mode will print log messages out to console, as well as to the log file. Otherwise, log messages can be found in the log file backup.log located in the same folder that the will be run from.


  1. To create a full backup:

    python ./ --full

    Upon success, the backup directory will contain one full backup directory:


    The name of the full backup directory will contain the word FULL followed by the timestamp associated with the backup. Inside this directory, a subdirectory will be created for each database that was backed up.

    The last_backup_name document is automatically updated after every successful backup, and will be used when an incremental backup is requested.

  2. To create an incremental backup:

    python ./ --inc

    Upon success, the backup directory will contain a new incremental backup:


    The new directory named INC_20151027_162019 contains a subdirectory for each database that was backed up, as with a full backup. The incremental backup will look similar to a full backup as the files in an incremental are hardlinked to the most recent full backup.


Previous backups are not deleted from the backup_directory upon a new backup creation.


To Restore from Backup:

  1. If a local SonarW service is running, stop it before restoring from backup.

  2. Find the backup directory from which you want to restore (FULL_* or INC_*)

  3. Inside this directory, you will find a directory for each database that was backed up.

    If you are restoring two databases (admin and sonargd) from a full backup named FULL_20151027_125827, you will see the following directories:


    Similarly, if restoring from an incremental backup named INC_20151027_162019, you will find:


    Where 20151027_162019 is the timestamp associated with the incremental backup.

  4. Copy the database directories of the databases you wish to restore into SONAR_HOME/data. For example, you may have:

  5. Delete the temporary cache (if it exists) that was used for the dbs; new cache files will be created when the sonard service restarts. For example:

  6. Restart the sonard service:

    sudo service sonard start