Page tree

SAYMON документация

Skip to end of metadata
Go to start of metadata

This article describes the process of saving backup copies, restoring and transferring system data between several installations.

MongoDB

Backup

In order to export data from MongoDB to an archive on the existing installation, execute the following script:

sudo /opt/saymon-scripts/mongodump.sh

Text of the script:

#!/bin/bash
BACKUP=/backups/mongo/mongodump-$(date +%F-%H-%M).gz
HOST='10.130.0.10'
LOGIN='saymon'
PASS='5tr43ewQ21'

# Outputs a log message, prefixed with current date-time.
log() {
    echo "[`date`] $1"
}

# Create MongoDB backup.
mongodump -h"$HOST" -u"$LOGIN" -p"$PASS" --db saymon --gzip --archive > "$BACKUP"

log "MongoDB stored to $BACKUP" 

By default the backup copy is created in the folder /backups/mongo.

In order to set periodic automatic creation of new copies and deletion the old ones, add the corresponding commands into crontab. For instance:

sudo crontab -e

0 */2 * * * /opt/saymon-scripts/mongodump.sh
10 */2 * * * ls -tr /backups/mongo | xargs realpath | head -n -6 | xargs rm

Restoring

In order to restore or import data into MongoDB on a new system installation, execute the following script:

sudo /opt/saymon-scripts/mongorestore.sh

Text of the script:

#!/bin/bash
HOST='10.130.0.10'
LOGIN='saymon'
PASS='5tr43ewQ21'

# Outputs a log message, prefixed with current date-time.
log() {
    echo "[`date`] $1"
}

# Directory for MongoDB backups.
DIR=/backups/mongo

# Ask user to specify dump file.
read  -p "Please specify backup file, e.g. mongodump-2021-04-15-14-10.gz: " BACKUP

# Check if BACKUP exists, remove DIR if ndeeded.
if [[ "$BACKUP" = */backups/mongo/* ]]; then
  BACKUP=$(sed 's/\/backups\/mongo\///' <<< "$BACKUP")
fi

if [ -f $DIR/$BACKUP ]; then
  log "Backup file $DIR/$BACKUP found!"
else
  log "Backup file $DIR/$BACKUP not found!"
  exit 1
fi

# Create MongoDB backup.
mongorestore -h"$HOST" -u"$LOGIN" -p"$PASS" --db saymon --drop --noIndexRestore --gzip --archive="$DIR/$BACKUP"
redis-cli -h 10.130.0.10 -a '$6$9UG8HCr0nqj$bVMZfvDKTobl' flushall

log "MongoDB, database saymon, restored from $DIR/$BACKUP"

OpenTSDB

Backup

In order to export data from OpenTSDB to an archive on the existing installation, execute the following script:

sudo /opt/saymon-scripts/hbasedump.sh

Text of the script:

#!/bin/bash
BACKUP=/backups/hbase/hbasedump-$(date +%F-%H-%M).tar.gz

# Outputs a log message, prefixed with current date-time.
log() {
    echo "[`date`] $1"
}

# Create HBase backup.
tar zcvf "$BACKUP" /var/lib/hbase

log "HBase stored to $BACKUP"

By default the backup copy is created in the folder /backups/hbase.

In order to set periodic automatic creation of new copies and deletion the old ones, add the corresponding commands into crontab. For instance:

sudo crontab -e

0 */2 * * * /opt/saymon-scripts/hbasedump.sh
10 */2 * * * ls -tr /backups/hbase | xargs realpath | head -n -6 | xargs rm

Restoring

In order to restore or import data into OpenTSDB on a new system installation, execute the following script:

sudo /opt/saymon-scripts/hbaserestore.sh

Text of the script:

#!/bin/bash
#
# Outputs a log message, prefixed with current date-time.
log() {
    echo "[`date`] $1"
}

# Directory for MongoDB backups.
DIR=/backups/hbase

# Ask user to specify dump file.
read  -p "Please specify backup file, e.g. hbasedump-2021-04-15-14-31.tar.gz: " BACKUP

# Check if BACKUP exists, remove DIR if ndeeded.
if [[ "$BACKUP" = */backups/hbase/* ]]; then
  BACKUP=$(sed 's/\/backups\/hbase\///' <<< "$BACKUP")
fi

if [ -f $DIR/$BACKUP ]; then
  log "Backup file $DIR/$BACKUP found!"
else
  log "Backup file $DIR/$BACKUP not found!"
  exit 1
fi

# Restore from BACKUP.
docker stop opentsdb
rm -rf /var/lib/hbase
tar xvf $DIR/$BACKUP -C /
docker start opentsdb

log "HBase restored from $DIR/$BACKUP"

Configuration files

It is necessary to make a copy of:

  • the /etc/saymon directory, which contains server configuration files;
  • the client configuration file /usr/local/saymon/client/client-config.js.

    In some cases the file  client-config.js can be stored in another directory. The directory can be found by either checking the nginx configuration file or using the following command:

    sudo find / -name "client-config.js"

In order to import configuration settings, it is necessary to paste:

  • the files from the previously saved directory with configurations files into the directory /etc/saymon;
  • the client configuration file into the directory /usr/local/saymon/client.
  • No labels