Welcome to Headwind MDM Q&A, where you can ask questions and receive answers from other members of the community.

Please do not post bug reports, missing feature requests, or demo inquiries. If you have such an inquiry, submit a contact form.

0 votes
Do you have a recommended backup scheme for server?  Such as - we can write a tar script and sftp to an offsite storage?

We would sql dump - tomcat directory and mdm directories.
by

1 Answer

0 votes

Here are sample scripts for doing backup and restore. They write backups to a backup directory - you can either mount a remote storage or update scripts so they send files using sftp.

Note that your directories may differ from default directories! Test these scripts before using in production!

backup-database.sh

#!/bin/sh

#

# This script makes a database backup and stores it to a backup directory

# (the directory should exist)

# Backups older than 2 days are removed

#

# To restore, drop and re-create the hmdm database, then run the command

# psql -U hmdm hmdm < hmdm-backupdate.sql

#

DIR=/var/backup/hmdm

DATESTR=$(date +%Y-%m-%d)

PGPASSWORD=topsecret 

export PGPASSWORD

pg_dump -h 127.0.0.1 -U hmdm hmdm > $DIR/hmdm-$DATESTR.sql

gzip -f $DIR/hmdm-$DATESTR.sql

find $DIR -type f -mtime +2 -exec rm {} \;

unset PGPASSWORD

backup-files.sh

#!/bin/sh

#

# This script makes Headwind MDM files backup and stores it to a backup directory

# (the directory should exist)

# Backups older than 2 days are removed

#

# To restore, run the script restore-files.sh hmdm-backupdate.tar.gz

#

TMP_DIR=/tmp

TOMCAT_DIR=/var/lib/tomcat9

HMDM_DIR=$TOMCAT_DIR/work

BACKUP_DIR=/var/backup/hmdm

FILES_DIR=files

PLUGINS_DIR=plugins

TOMCAT_APP=ROOT

DATESTR=$(date +%Y-%m-%d)

BACKUP_TMP_DIR=$TMP_DIR/hmdm-$DATESTR

mkdir $BACKUP_TMP_DIR 

cp -r $HMDM_DIR/$FILES_DIR $BACKUP_TMP_DIR

cp -r $HMDM_DIR/$PLUGINS_DIR $BACKUP_TMP_DIR

cp $HMDM_DIR/log4j-hmdm.xml $BACKUP_TMP_DIR

cp $TOMCAT_DIR/conf/Catalina/localhost/$TOMCAT_APP.xml $BACKUP_TMP_DIR

cp $TOMCAT_DIR/webapps/$TOMCAT_APP.war $BACKUP_TMP_DIR

cd $TMP_DIR

tar -zcf hmdm-$DATESTR.tar.gz hmdm-$DATESTR

rm -rf $BACKUP_TMP_DIR

mv hmdm-$DATESTR.tar.gz $BACKUP_DIR

find $BACKUP_DIR -type f -mtime +2 -exec rm {} \;

restore-files.sh

#!/bin/bash

#

# This script restores Headwind MDM files from the backup

# Use this script with care because it may overwrite the existing installation!

#

TMP_DIR=/tmp

TOMCAT_DIR=/var/lib/tomcat9

HMDM_DIR=$TOMCAT_DIR/work

FILES_DIR=files

PLUGINS_DIR=plugins

TOMCAT_APP=ROOT

if [ ! -f "$1" ]; then

    echo "Usage: restore-files.sh hmdm-backupdate.tar.gz"

    return

fi

BACKUP_DIR="${1/.tar.gz/}"

cd $TMP_DIR

tar -zxf $1

cd $BACKUP_DIR

cp -r $FILES_DIR $HMDM_DIR/$FILES_DIR

cp -r $PLUGINS_DIR $HMDM_DIR/$PLUGINS_DIR

cp log4j-hmdm.xml $HMDM_DIR

cp $TOMCAT_APP.xml $TOMCAT_DIR/conf/Catalina/localhost

cp $TOMCAT_APP.war $TOMCAT_DIR/webapps

cd $TMP_DIR

rm -rf $BACKUP_DIR

by (32.7k points)
edited by
...