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 - for example, mongodb://username:password@192.168.1.1:27117.
  • server_host_uri: URI of the server host - for example, qa@192.168.1.1.

Installation and setup

  1. Download and install the SonarBackup package, refer to the SonarW documentation for prerequisites and OS specific details:

    http://sonarwdocs.jsonar.com/latest/installsonar.html
    
  2. Create a backup directory, make sure that sonarw user have full previliges 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/id_rsa.pub’ from the backup machine to ~/sonarw/.ssh/authorized_keys to the SonarW node, for example:

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

    sudo su sonarw
    cd ~sonarw/.ssh (create .ssh folder if doesn't exist).
    cat /tmp/id_rsa.pub >> 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 id_rsa.pub:

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

Usage

Run the backup script to create a full or incremental backup as follows::

backup.py (–inc | –full) [–verbose –debug –config=<full path to config file>] backup.py -h | –help

Options:

  • -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 backup.py will be run from.

Example

  1. To create a full backup:

    python ./backup.py --full
    

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

    backup_dir/FULL_20151027_125827
    backup_dir/last_backup_name
    

    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 ./backup.py --inc
    

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

    backup_dir/FULL_20151027_125827
    backup_dir/INC_20151027_162019
    backup_dir/last_backup_name
    

    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.

Note

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

Restore

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 the 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:

    FULL_20151027_125827/admin
    FULL_20151027_125827/sonargd
    

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

    INC_20151027_162019/admin
    INC_20151027_162019/sonargd
    

    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:

    SONAR_HOME/data/admin
    SONAR_HOME/data/sonargd
    
  5. Delete the temporary cache (if exists), that was used for the dbs, new cache files will be created when the sonard service will restart. For example:

    SONAR_HOME/cache/admin
    SONAR_HOME/cache/sonargd
    
  6. Restart the sonard service:

    sudo service sonard start