Correction du script de sauvegarde
This commit is contained in:
parent
133e8fcd05
commit
420caf4aa6
1 changed files with 22 additions and 30 deletions
|
@ -9,48 +9,41 @@ export OS_INTERFACE=public
|
|||
export OS_APPLICATION_CREDENTIAL_ID=xxxx
|
||||
export OS_APPLICATION_CREDENTIAL_SECRET=xxxx
|
||||
|
||||
#Daily Retention
|
||||
DAILY_RETENTION=7
|
||||
export TODAY=$(date +"%Y-%m-%d_%HH%M")
|
||||
export LOG_FILE=/var/log/backup/OpenStack_Vms_And_Volumes_${TODAY}.log
|
||||
|
||||
#Daily_Retention
|
||||
export DAILY_RETENTION=15
|
||||
|
||||
#Delay to Check Backup in seconds
|
||||
CHECK_BACKUP_DELAY=3600
|
||||
|
||||
TODAY=$(date +"%Y-%m-%d_%HH%M")
|
||||
|
||||
PROJECT_DIR=/opt/backup
|
||||
LOG_FILE=${PROJECT_DIR}/log/backup_${TODAY}.log
|
||||
ERR_FILE=${PROJECT_DIR}/log/backup.err
|
||||
|
||||
#Let's GO
|
||||
BCK_VOLUMES_LIST=()
|
||||
BCK_SERVERS_LIST=()
|
||||
|
||||
cat /dev/null > ${ERR_FILE}
|
||||
|
||||
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 of instances to be backed up" >>${LOG_FILE} 2>&1
|
||||
echo "======================================================" >>${LOG_FILE} 2>&1
|
||||
|
||||
if SERVERS=$(/usr/bin/openstack server list -f json| jq -r '.[].Name'); then
|
||||
|
||||
date +"[%Y-%m-%d_%HH%M] ---> Server(s) Found" >>${LOG_FILE} 2>&1
|
||||
date +"[%Y-%m-%d_%HH%M] ---> Instance(s) found" >>${LOG_FILE} 2>&1
|
||||
for SERVER in $SERVERS
|
||||
do
|
||||
SNAPSHOT_SERVER=${SERVER}_${TODAY}
|
||||
|
||||
date +"[%Y-%m-%d_%HH%M] ------> [Srv : ${SERVER}] === === Starting Backup === ===" >>${LOG_FILE} 2>&1
|
||||
date +"[%Y-%m-%d_%HH%M] ------> [Srv : ${SERVER}] ---> Listing volumes attached" >>${LOG_FILE} 2>&1
|
||||
date +"[%Y-%m-%d_%HH%M] ------> [Instance : ${SERVER}] === === Launching the backup === ===" >>${LOG_FILE} 2>&1
|
||||
date +"[%Y-%m-%d_%HH%M] ------> [Instance : ${SERVER}] ---> Listing of volumes attached" >>${LOG_FILE} 2>&1
|
||||
|
||||
if VOLUMES_ATTACHED=$(/usr/bin/openstack server volume list ${SERVER} -f json | jq -r '.[]."Volume ID"'); then
|
||||
|
||||
date +"[%Y-%m-%d_%HH%M] ------> [Srv : ${SERVER}] ------> Found volumes attached" >>${LOG_FILE} 2>&1
|
||||
date +"[%Y-%m-%d_%HH%M] ------> [Srv : ${SERVER}] ------> Attached volume(s) Found" >>${LOG_FILE} 2>&1
|
||||
|
||||
for VOLUME_ATTACHED_ID in $VOLUMES_ATTACHED
|
||||
do
|
||||
VOLUME_ATTACHED_NAME=$(/usr/bin/openstack volume show ${VOLUME_ATTACHED_ID} -f json | jq -r '.name')
|
||||
BCK_VOLUME_ATTACHED_NAME=Backup_${VOLUME_ATTACHED_NAME}_${TODAY}
|
||||
|
||||
date +"[%Y-%m-%d_%HH%M] ------> [Srv : ${SERVER}] ------> Starting Backup volume from ${VOLUME_ATTACHED_NAME} to ${BCK_VOLUME_ATTACHED_NAME}" >>${LOG_FILE} 2>&1
|
||||
date +"[%Y-%m-%d_%HH%M] ------> [Srv : ${SERVER}] ------> Launching the backup of the volume ${VOLUME_ATTACHED_NAME} to ${BCK_VOLUME_ATTACHED_NAME}" >>${LOG_FILE} 2>&1
|
||||
BCK_VOLUMES_LIST+=(${BCK_VOLUME_ATTACHED_NAME})
|
||||
/usr/bin/openstack volume backup create --name ${BCK_VOLUME_ATTACHED_NAME} ${VOLUME_ATTACHED_NAME} --force >>${LOG_FILE} 2>&1
|
||||
done
|
||||
|
@ -63,14 +56,15 @@ if SERVERS=$(/usr/bin/openstack server list -f json| jq -r '.[].Name'); then
|
|||
|
||||
BCK_SERVER=Backup_${SERVER}_${TODAY}
|
||||
|
||||
date +"[%Y-%m-%d_%HH%M] ------> [Srv : ${SERVER}] ---> Starting Snapshot from ${SERVER} to ${BCK_SERVER}" >>${LOG_FILE} 2>&1
|
||||
date +"[%Y-%m-%d_%HH%M] ------> [Srv : ${SERVER}] ---> Launching the Snapshot of the instance ${SERVER} to ${BCK_SERVER}" >>${LOG_FILE} 2>&1
|
||||
BCK_SERVERS_LIST+=(${BCK_SERVER})
|
||||
|
||||
/usr/bin/openstack server backup create --rotate ${DAILY_RETENTION} --name ${BCK_SERVER} ${SERVER} >>${LOG_FILE} 2>&1
|
||||
|
||||
date +"[%Y-%m-%d_%HH%M] ------> [Srv : ${SERVER}] === === End of Backup === ===" >>${LOG_FILE} 2>&1
|
||||
date +"[%Y-%m-%d_%HH%M] ------> [Srv : ${SERVER}] === === End of the backup === ===" >>${LOG_FILE} 2>&1
|
||||
done
|
||||
else
|
||||
echo "No Server found" >>${LOG_FILE} 2>&1
|
||||
echo "No instance found" >>${LOG_FILE} 2>&1
|
||||
fi
|
||||
|
||||
echo "======================================================" >>${LOG_FILE} 2>&1
|
||||
|
@ -79,7 +73,7 @@ echo "======================================================" >>${LOG_FILE} 2>&
|
|||
|
||||
MAXIMUM_TIMESTAMP=`date -d '+'${CHECK_BACKUP_DELAY}' seconds' '+%s'`
|
||||
|
||||
date +"[%Y-%m-%d_%HH%M] => Checking Backup Volumes" >>${LOG_FILE} 2>&1
|
||||
date +"[%Y-%m-%d_%HH%M] => Checking the backup of volumes" >>${LOG_FILE} 2>&1
|
||||
for CHECK_BCK_VOLUME in ${BCK_VOLUMES_LIST}
|
||||
do
|
||||
RESULT=false
|
||||
|
@ -90,7 +84,6 @@ do
|
|||
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
|
||||
|
||||
|
@ -111,7 +104,6 @@ do
|
|||
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
|
||||
|
||||
|
@ -136,7 +128,7 @@ if OLD_VOLUMES=$(/usr/bin/openstack volume backup list -f json | jq -r '.[].Name
|
|||
for OLD_VOLUME in $OLD_VOLUMES
|
||||
do
|
||||
date +"[%Y-%m-%d_%HH%M] ------> Remove Backup Volume ${OLD_VOLUME}" >>${LOG_FILE} 2>&1
|
||||
/usr/local/bin/openstack volume backup delete ${OLD_VOLUME} >>${LOG_FILE} 2>&1
|
||||
/usr/bin/openstack volume backup delete ${OLD_VOLUME} >>${LOG_FILE} 2>&1
|
||||
|
||||
done
|
||||
else
|
||||
|
@ -154,7 +146,7 @@ if OLD_INSTANCES=$(/usr/bin/openstack image list -f json| jq -r '.[].Name|select
|
|||
for OLD_INSTANCE in $INSTANCES
|
||||
do
|
||||
date +"[%Y-%m-%d_%HH%M] ------> Remove Backup Instance ${OLD_INSTANCE}" >>${LOG_FILE} 2>&1
|
||||
/usr/local/bin/openstack image delete ${OLD_INSTANCE} >>${LOG_FILE} 2>&1
|
||||
/usr/bin/openstack image delete ${OLD_INSTANCE} >>${LOG_FILE} 2>&1
|
||||
|
||||
done
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue