Data Backup and Migration
To migrate OpsAny to a new environment or to back up data routinely, you need to understand where OpsAny stores data. There are three parts:
- MySQL database: every OpsAny SaaS platform creates a MySQL database named after its APPID, with the APPID as the username and a password that is custom or generated during installation.
- MongoDB database: OpsAny SaaS platforms such as the Workbench and the Resource Platform store data in MongoDB, creating a database named after the APPID with the APPID as the username.
- uploads directory: everything users upload or write — scripts and so on — is stored in INSTALL_PATH/uploads.
Option 1: install OpsAny afresh, then migrate the data (recommended)
-
- Install a fresh OpsAny platform: in the new environment, install the same version as the old platform following the official documentation. Migration does not support upgrades, so if you are not on the latest version, upgrade first.
-
- Back up MySQL, MongoDB, and uploads from the old platform and copy them to the new host.
-
- Import the old platform's data and verify it.
Option 2: image migration.
-
- Take a VM snapshot of the original platform host.
-
- Start the new host instance in the new environment.
-
- Update every configuration file with the new IP address (all files under ${INSTALL_PATH}/conf, roughly 20 of them).
Backing up MySQL
| Parameter |
Description |
| MyUSER |
Database username |
| MyPASS |
Database password |
| MyHOST |
Database host address |
| DEST |
Backup destination directory |
#!/bin/bash
# Shell script to backup MySQL database
# Set these variables
MyUSER="" # DB_USERNAME
MyPASS="" # DB_PASSWORD
MyHOST="" # DB_HOSTNAME
# Backup Dest directory
DEST=""
# Email for notifications
# EMAIL=""
# How many days old files must be to be removed
DAYS=5
# Linux bin paths
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
GZIP="$(which gzip)"
# Get date in dd-mm-yyyy format
NOW="$(date +"%Y-%m-%d_%s")"
# Create Backup sub-directories
MBD="$DEST/$NOW"
install -d $MBD
# DB skip list
SKIP="information_schema
another_one_db"
# Get all databases
DBS="$($MYSQL -h $MyHOST -u $MyUSER -p$MyPASS -Bse 'show databases')"
# Archive database dumps
for db in $DBS
do
skipdb=-1
if [ "$SKIP" != "" ];
then
for i in $SKIP
do
[ "$db" == "$i" ] && skipdb=1 || :
done
fi
if [ "$skipdb" == "-1" ] ; then
FILE="$MBD/$db.sql"
$MYSQLDUMP -h $MyHOST -u $MyUSER -p$MyPASS --single-transaction $db > $FILE
fi
done
# Archive the directory, send mail and cleanup
cd $DEST
tar -cf $NOW.tar $NOW
$GZIP -9 $NOW.tar
# echo "MySQL backup is completed! Backup name is $NOW.tar.gz" | mail -s "MySQL backup" $EMAIL
rm -rf $NOW
# Remove old files
find $DEST -mtime +$DAYS -exec rm -f {} \;
Backing up MongoDB
| Parameter |
Description |
| DB_BACKUP_PATH |
Backup destination directory |
| MONGO_HOST |
Database host address |
| MONGO_PORT |
Database port |
| AUTH_ENABLED |
Whether authentication is enabled |
| MONGO_USER |
Database username |
| MONGO_PASSWD |
Database password |
| DATABASE_NAMES |
Databases to back up |
#!/bin/bash
##
## MongoDB Database Backup Script
##
export PATH=/bin:/usr/bin:/usr/local/bin
TODAY=`date +"%Y_%m_%d"`
DB_BACKUP_PATH=''
MONGO_HOST=''
MONGO_PORT=''
# If mongodb is protected with username password.
# Set AUTH_ENABLED to 1
# and add MONGO_USER and MONGO_PASSWD values correctly
AUTH_ENABLED=1
MONGO_USER=''
MONGO_PASSWD=''
# Set DATABASE_NAMES to "ALL" to backup all databases.
# or specify databases names seprated with space to backup
# specific databases only.
DATABASE_NAMES='ALL'
#DATABASE_NAMES='mydb db2 newdb'
## Number of days to keep local backup copy
BACKUP_RETAIN_DAYS=30
mkdir -p ${DB_BACKUP_PATH}/${TODAY}
AUTH_PARAM=""
if [ ${AUTH_ENABLED} -eq 1 ]; then
AUTH_PARAM=" --username ${MONGO_USER} --password ${MONGO_PASSWD} "
fi
if [ ${DATABASE_NAMES} = "ALL" ]; then
echo "You have choose to backup all databases"
mongodump --host ${MONGO_HOST} --port ${MONGO_PORT} ${AUTH_PARAM} --out ${DB_BACKUP_PATH}/${TODAY}/
else
echo "Running backup for selected databases"
for DB_NAME in ${DATABASE_NAMES}
do
mongodump --host ${MONGO_HOST} --port ${MONGO_PORT} --db ${DB_NAME} ${AUTH_PARAM} --out ${DB_BACKUP_PATH}/${TODAY}/
done
fi
## Remove backups older than {BACKUP_RETAIN_DAYS} days ##
DBDELDATE=`date +"%Y_%m_%d" --date="${BACKUP_RETAIN_DAYS} days ago"`
if [ ! -z ${DB_BACKUP_PATH} ];then
cd ${DB_BACKUP_PATH}
if [ ! -z ${DBDELDATE} ] && [ -d ${DBDELDATE} ];then
rm -rf ${DBDELDATE}
fi
fi