#!/bin/bash

set -u -o pipefail

NOW=$(date +"%Y-%m-%d-%H%M")
DEPLOY_PATH=/home/docker/deploy
BACKUP_PATH=${DEPLOY_PATH}/backup/static.homolo.net/${NOW}
APP_PATH=/data/static.homolo.net

echo "Create backup directory: ${BACKUP_PATH}..."
mkdir -p ${BACKUP_PATH}

ls -l ${DEPLOY_PATH}/${1}.war
echo "Copy the ${1} directory to the backup directory"
cp -Raf ${APP_PATH}/${1} ${BACKUP_PATH}
rm -rf ${APP_PATH}/${1}
mkdir ${APP_PATH}/${1}
cd ${APP_PATH}/${1}
unzip ${DEPLOY_PATH}/${1}.war
rm -r WEB-INF
