2019-07-11 14:53:30 +00:00
|
|
|
#!/bin/bash
|
2020-03-31 14:03:59 +00:00
|
|
|
#Absolute path to this script
|
|
|
|
SCRIPT=$(readlink -f $0)
|
|
|
|
#Absolute path this script is in
|
|
|
|
SCRIPTPATH=$(dirname $SCRIPT)
|
|
|
|
|
|
|
|
cd $SCRIPTPATH
|
|
|
|
|
2019-11-06 14:53:27 +00:00
|
|
|
test -z $1 || HOST="_$1"
|
|
|
|
test -z $2 || INSTANCE="_$2"
|
2020-02-22 20:25:29 +00:00
|
|
|
test -f ~/secrets.tar.gz.enc || { echo "ERROR: ~/secrets.tar.gz.enc not found, exiting."; exit 1; }
|
2020-03-31 14:03:59 +00:00
|
|
|
openssl enc -aes-256-cbc -d -in ~/secrets.tar.gz.enc \
|
|
|
|
| sudo tar -zxv --strip 2 secrets/docker-mysql-stack${HOST}${INSTANCE}/debian.cnf \
|
|
|
|
|| { echo "Could not extract from secrets archive, exiting."; rm -f ~/secrets.tar.gz.enc; exit 1; }
|
2020-02-26 16:36:09 +00:00
|
|
|
sudo chown root. debian.cnf
|
2020-02-22 20:25:29 +00:00
|
|
|
|
|
|
|
test -f ~/openrc.sh || { echo "ERROR: ~/openrc.sh not found, exiting."; exit 1; }
|
|
|
|
source ~/openrc.sh
|
|
|
|
export OS_REGION_NAME=GRA
|
|
|
|
test -f ~/duplicity_password.sh || { echo "ERROR: ~/duplicity_password.sh not found, exiting."; exit 1; }
|
|
|
|
source ~/duplicity_password.sh
|
|
|
|
|
|
|
|
sudo docker image inspect duplicity:latest &> /dev/null ||{ echo "ERROR: duplicity:latest image not found, exiting."; exit 1; }
|
|
|
|
|
|
|
|
rm -rf ~/build
|
|
|
|
mkdir -p ~/build
|
2020-02-26 16:36:09 +00:00
|
|
|
for name in docker-mysql
|
2020-02-22 20:25:29 +00:00
|
|
|
do
|
|
|
|
sudo -E docker run --rm -e SWIFT_USERNAME=$OS_USERNAME \
|
|
|
|
-e SWIFT_PASSWORD=$OS_PASSWORD \
|
|
|
|
-e SWIFT_AUTHURL=$OS_AUTH_URL \
|
|
|
|
-e SWIFT_AUTHVERSION=$OS_IDENTITY_API_VERSION \
|
|
|
|
-e SWIFT_TENANTNAME=$OS_TENANT_NAME \
|
|
|
|
-e SWIFT_REGIONNAME=$OS_REGION_NAME \
|
|
|
|
-e PASSPHRASE=$PASSPHRASE \
|
|
|
|
--name backup-restore -v ~/build:/mnt/build --entrypoint /bin/bash duplicity:latest \
|
|
|
|
-c "duplicity restore --name bootstrap --file-to-restore ${name}.tar.gz swift://bootstrap /mnt/build/${name}.tar.gz"
|
|
|
|
tar -xzf ~/build/${name}.tar.gz -C ~/build/
|
|
|
|
done
|
|
|
|
|
2020-02-26 16:36:09 +00:00
|
|
|
unset VERSION_MYSQL
|
2020-02-22 20:25:29 +00:00
|
|
|
DIRECTORY=$(pwd)
|
|
|
|
cd ~/build/docker-mysql; export VERSION_MYSQL=$(git show-ref --head| head -1 | cut -f 1|cut -c -10); cd $DIRECTORY
|
|
|
|
|
|
|
|
sudo docker build -t mysql-server:$VERSION_MYSQL ~/build/docker-mysql
|
|
|
|
|
2020-03-31 14:03:59 +00:00
|
|
|
sudo -E bash -c 'docker-compose up --no-start --force-recreate'
|
2020-02-26 16:36:09 +00:00
|
|
|
# --force-recreate is used to recreate container when a file has changed
|
2019-07-11 21:03:13 +00:00
|
|
|
# We cannot remove the secrets files or restarting the container would become impossible
|
2020-02-26 16:36:09 +00:00
|
|
|
# rm -f debian.cnf
|
2020-02-22 20:25:29 +00:00
|
|
|
rm -rf ~/build
|