####################################################################
# rhevm Backup script                                              #
# create : KangWoo Lee                                             #
# date   : 2013.03.12                                              #
#                                                                  #
# Variables                                                        #
# DEST_DIR : backup archive creating directory                     #
# TARGETS  : backup target files                                   #
#                                                                  #
####################################################################
#!/bin/sh
DEST_DIR=.
DATE=`date +%F`
LINE="=========================================="


echo $LINE
echo "[$DATE] Backup Script Start"
echo $LINE

# Backup Target define

TARGETS=(
/etc/jbossas/jbossas.conf
/etc/rhevm/
/etc/yum/pluginconf.d/versionlock.list
/etc/pki/rhevm/
/etc/jbossas/rhevm-slimmed/
/var/lib/jbossas/server/rhevm-slimmed
/usr/share/rhevm-reports-server/buildomatic
/usr/share/rhevm/conf/iptables.example
/usr/share/rhevm/kerberos/krb5.conf
/usr/share/rhevm/dbscripts/create_db.sh.log
/usr/share/rhevm/rhevm.ear/rhevmanager.war/ExternalConfig.txt
/usr/share/rhevm/rhevm.ear/rhevmanager.war/ServerParameters.js
#/usr/share/rhevm-reports/reports-INSERT_VERSION_NUMBER/resources/organizations/rhevmreports/Resources/JDBC/data_sources/rhevm.xml
#/usr/share/rhevm-reports/reports-INSERT_VERSION_NUMBER/users/rhevmreports/rhevm-002dadmin.xml
/usr/share/rhevm-reports/
#/usr/share/rhevm-reports-server/buildomatic/default_master.properties
#/usr/share/rhevm-reports-server/buildomatic/install.xml
#/usr/share/rhevm-reports-server/buildomatic/setup.xml
/usr/share/rhevm-reports-server/buildomatic/
/root/.pgpass
/root/.rnd
)

# Destination directory check
if [ ! -e $DEST_DIR ]
then
	echo "Destination directory is NOT EXISTS! creating..."
	mkdir -p $DEST_DIR
fi

# File Check
for T in ${TARGETS[*]}
do
	#echo $T
	if [ -e $T ]
		then
			echo "$T is exists"
		else
			echo "$T is not exists"
	fi
done

# Backup Archive Create
tar -cvzf $DEST_DIR/rhevm_backup-$DATE.tgz ${TARGETS[*]}

echo $LINE
echo "Backup End"
echo $LINE