fix backup openstack script
This commit is contained in:
parent
0fae301077
commit
133e8fcd05
1 changed files with 45 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
#OS Credentials and settings
|
||||||
export OS_AUTH_TYPE=xxxx
|
export OS_AUTH_TYPE=xxxx
|
||||||
export OS_AUTH_URL=xxxx
|
export OS_AUTH_URL=xxxx
|
||||||
export OS_IDENTITY_API_VERSION=xxx
|
export OS_IDENTITY_API_VERSION=xxx
|
||||||
|
@ -8,15 +9,24 @@ export OS_INTERFACE=public
|
||||||
export OS_APPLICATION_CREDENTIAL_ID=xxxx
|
export OS_APPLICATION_CREDENTIAL_ID=xxxx
|
||||||
export OS_APPLICATION_CREDENTIAL_SECRET=xxxx
|
export OS_APPLICATION_CREDENTIAL_SECRET=xxxx
|
||||||
|
|
||||||
TODAY=$(date +"%Y-%m-%d_%HH%M")
|
#Daily Retention
|
||||||
DAILY_RETENTION=7
|
DAILY_RETENTION=7
|
||||||
|
|
||||||
|
#Delay to Check Backup in seconds
|
||||||
|
CHECK_BACKUP_DELAY=3600
|
||||||
|
|
||||||
|
TODAY=$(date +"%Y-%m-%d_%HH%M")
|
||||||
|
|
||||||
PROJECT_DIR=/opt/backup
|
PROJECT_DIR=/opt/backup
|
||||||
LOG_FILE=${PROJECT_DIR}/log/backup_${TODAY}.log
|
LOG_FILE=${PROJECT_DIR}/log/backup_${TODAY}.log
|
||||||
|
ERR_FILE=${PROJECT_DIR}/log/backup.err
|
||||||
|
|
||||||
|
#Let's GO
|
||||||
BCK_VOLUMES_LIST=()
|
BCK_VOLUMES_LIST=()
|
||||||
BCK_SERVERS_LIST=()
|
BCK_SERVERS_LIST=()
|
||||||
|
|
||||||
|
cat /dev/null > ${ERR_FILE}
|
||||||
|
|
||||||
echo "======================================================" >>${LOG_FILE} 2>&1
|
echo "======================================================" >>${LOG_FILE} 2>&1
|
||||||
date +"[%Y-%m-%d_%HH%M] - Listing instance to be backed up" >>${LOG_FILE} 2>&1
|
date +"[%Y-%m-%d_%HH%M] - Listing instance to be backed up" >>${LOG_FILE} 2>&1
|
||||||
echo "======================================================" >>${LOG_FILE} 2>&1
|
echo "======================================================" >>${LOG_FILE} 2>&1
|
||||||
|
@ -67,17 +77,48 @@ echo "======================================================" >>${LOG_FILE} 2>&
|
||||||
date +"[%Y-%m-%d_%HH%M] - Confirm that's all backup is OK" >>${LOG_FILE} 2>&1
|
date +"[%Y-%m-%d_%HH%M] - Confirm that's all backup is OK" >>${LOG_FILE} 2>&1
|
||||||
echo "======================================================" >>${LOG_FILE} 2>&1
|
echo "======================================================" >>${LOG_FILE} 2>&1
|
||||||
|
|
||||||
date +"[%Y-%m-%d_%HH%M] => Checking Backup Volumes" >>${LOG_FILE} 2>&1
|
MAXIMUM_TIMESTAMP=`date -d '+'${CHECK_BACKUP_DELAY}' seconds' '+%s'`
|
||||||
|
|
||||||
|
date +"[%Y-%m-%d_%HH%M] => Checking Backup Volumes" >>${LOG_FILE} 2>&1
|
||||||
for CHECK_BCK_VOLUME in ${BCK_VOLUMES_LIST}
|
for CHECK_BCK_VOLUME in ${BCK_VOLUMES_LIST}
|
||||||
do
|
do
|
||||||
##TODO faire une variable qui recup tous les instances sauvegardées précédements et checker
|
RESULT=false
|
||||||
|
while [ ! "$RESULT" = "true" ];
|
||||||
|
do
|
||||||
|
date +"[%Y-%m-%d_%HH%M] Checking Backup for ${CHECK_BCK_VOLUME} and waiting 60 secondes" >>${LOG_FILE} 2>&1
|
||||||
|
|
||||||
|
CURRENT_TIMESTAMP=`date +%s`
|
||||||
|
if [ "$CURRENT_TIMESTAMP" -gt "$MAXIMUM_TIMESTAMP" ]; then
|
||||||
|
date +"[%Y-%m-%d_%HH%M] [ERROR] backup for ${CHECK_BCK_VOLUME} verification time expired" >>${LOG_FILE} 2>&1
|
||||||
|
date +"[%Y-%m-%d_%HH%M] [ERROR] backup for ${CHECK_BCK_VOLUME} verification time expired" >>${ERR_FILE}
|
||||||
|
exit -1
|
||||||
|
fi
|
||||||
|
|
||||||
|
RESULT=`openstack volume backup show ${CHECK_BCK_VOLUME} -f json | jq -r '.status == "available"'`
|
||||||
|
sleep 60
|
||||||
|
done
|
||||||
|
date +"[%Y-%m-%d_%HH%M] Backup Volume ${CHECK_BCK_VOLUME} is OK" >>${LOG_FILE} 2>&1
|
||||||
done
|
done
|
||||||
|
|
||||||
date +"[%Y-%m-%d_%HH%M] => Checking Backup Instance" >>${LOG_FILE} 2>&1
|
date +"[%Y-%m-%d_%HH%M] => Checking Backup Instance" >>${LOG_FILE} 2>&1
|
||||||
for CHECK_BCK_SERVER in ${BCK_SERVERS_LIST}
|
for CHECK_BCK_SERVER in ${BCK_SERVERS_LIST}
|
||||||
do
|
do
|
||||||
##TODO faire une variable qui recup tous les instances sauvegardées précédements et checker
|
RESULT=false
|
||||||
|
while [ ! "$RESULT" = "true" ];
|
||||||
|
do
|
||||||
|
date +"[%Y-%m-%d_%HH%M] Checking Backup for ${CHECK_BCK_SERVER} and waiting 60 secondes" >>${LOG_FILE} 2>&1
|
||||||
|
|
||||||
|
CURRENT_TIMESTAMP=`date +%s`
|
||||||
|
if [ "$CURRENT_TIMESTAMP" -gt "$MAXIMUM_TIMESTAMP" ]; then
|
||||||
|
date +"[%Y-%m-%d_%HH%M] [ERROR] backup for ${CHECK_BCK_SERVER} verification time expired" >>${LOG_FILE} 2>&1
|
||||||
|
date +"[%Y-%m-%d_%HH%M] [ERROR] backup for ${CHECK_BCK_VOLUME} verification time expired" >>${ERR_FILE}
|
||||||
|
exit -1
|
||||||
|
fi
|
||||||
|
|
||||||
|
RESULT=`/usr/bin/openstack image show ${CHECK_BCK_SERVER} -f json | jq -r '.properties.image_state == "available" and .status == "active"'`
|
||||||
|
sleep 60
|
||||||
|
done
|
||||||
|
date +"[%Y-%m-%d_%HH%M] Backup Instance ${CHECK_BCK_SERVER} is OK" >>${LOG_FILE} 2>&1
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "======================================================" >>${LOG_FILE} 2>&1
|
echo "======================================================" >>${LOG_FILE} 2>&1
|
||||||
|
|
Loading…
Reference in a new issue