#!/bin/bash
#
# Backup script wrapper
#
NOW=$(date +"%Y-%m-%d-%H-%M-%S")
VB_VM_NAME=$1
#
# Run user check
if [ "$UID" -eq 0 ]
then echo "This script should NOT be run as root."
exit 1
fi
#
# Source config file
if [ ! -f ~/.vbconfig ]; then
echo "Config File ~/.vbconfig not found!"
echo "Run: set-folders to create .vbconfig"
exit 1
fi
. ~/.vbconfig
#
if [ ! -d "$VB_LOG_LOC" ]; then
echo "Log Directory: $VB_LOG_LOC NOT found"
exit 1
fi
#
BACKUP_LOG_FILE="${VB_LOG_LOC}/bk_${NOW}_${VB_VM_NAME}.log"
#
$VB_BIN_LOC/430-backup-vm.bash "$VB_VM_NAME" > $BACKUP_LOG_FILE 2>&1
#
# Delete backup log files older than 31 days
/usr/bin/find ${VB_LOG_LOC}/bk_*.log -mtime +31 -exec rm {} \;
#
exit