Last active
February 21, 2019 05:31
-
-
Save mark-church/9963b95910fe05e0f902af728dbbf9f6 to your computer and use it in GitHub Desktop.
A backup tool that backs up UCP and DTR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# set environment variables | |
USERNAME="admin" | |
PASSWORD="fake-password" | |
UCP_URL="54.190.20.45" | |
UCP_VERSION="2.1.5" | |
DTR_URL="34.214.139.101" | |
DTR_VERSION="2.3.3" | |
DTR_REPLICA="5007fbad4136" | |
ucp-backup() { | |
echo "----------- Docker EE Backup Tool -----------" | |
echo "" | |
echo "" | |
# Timeout required to allow user to cancel backup | |
echo "Starting UCP backup in 20 seconds." | |
echo "This UCP controller will temporarily shut down but an HA UCP will remain up." | |
sleep 20 | |
# Health checking for this UCP controller before backup | |
UCP_HEALTH=$(curl -k -s "https://${UCP_URL}/_ping") | |
if [ "${UCP_HEALTH}" != "OK" ]; then | |
echo "UCP Controller ${UCP_URL} returned bad health. Exiting backup script." | |
exit 1 | |
fi | |
echo "UCP health is OK" | |
UCP_BACKUP_NAME="ucp-${UCP_VERSION}-backup-$(date +%F-%R).tar" | |
UCP_ID=$(docker run --rm -i --name ucp -v /var/run/docker.sock:/var/run/docker.sock "docker/ucp:${UCP_VERSION}" id 2> /dev/null) | |
echo "UCP backup starting ..." | |
docker run --rm -i --name ucp \ | |
-v /var/run/docker.sock:/var/run/docker.sock \ | |
"docker/ucp:${UCP_VERSION}" backup \ | |
--id "${UCP_ID}" \ | |
--debug > "$UCP_BACKUP_NAME" | |
if [ $(/bin/ls -ls $UCP_BACKUP_NAME | awk '{print $6}' | bc) == 0 ]; then | |
echo "Backup was unsucessful. Run UCP backup manually." | |
exit 1 | |
fi | |
echo "UCP backup complete and saved as $UCP_BACKUP_NAME" | |
} | |
dtr-backup() { | |
# Timeout required to allow UCP to come backup. UCP was restarted in previous step. | |
echo "Starting DTR backup in 30 seconds. DTR will continue running during the backup." | |
sleep 30 | |
# Health checking DTR replica before backup | |
DTR_HEALTH=$(curl -k -s "https://${DTR_URL}/health" | jq ".Healthy") | |
if [ "${DTR_HEALTH}" != "true" ]; then | |
echo "DTR Replica ${DTR_URL} returned bad health. Exiting backup script." | |
exit 1 | |
fi | |
echo "DTR health is OK" | |
DTR_BACKUP_NAME="dtr-${DTR_VERSION}-backup-$(date +%F-%R).tar" | |
echo "DTR backup starting ..." | |
docker run -i --rm "docker/dtr:${DTR_VERSION}" backup \ | |
--debug \ | |
--ucp-username "${USERNAME}" \ | |
--ucp-password "${PASSWORD}" \ | |
--ucp-insecure-tls \ | |
--existing-replica-id "${DTR_REPLICA}" \ | |
--ucp-url "https://${UCP_URL}" > "$DTR_BACKUP_NAME" | |
if [ $(/bin/ls -ls $DTR_BACKUP_NAME | awk '{print $6}' | bc) == 0 ]; then | |
echo "Backup was unsucessful. Run DTR backup manually." | |
exit 1 | |
fi | |
echo "DTR backup complete and saved as $DTR_BACKUP_NAME" | |
} | |
#Entrypoint for program | |
ucp-backup | |
dtr-backup | |
echo "UCP and DTR backups are complete. Remember to test the backups with a UCP & DTR restore from time to time." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment