Actualiser Backup_OpenStack_Vms_And_Volumes.sh

This commit is contained in:
nono 2024-01-26 16:40:44 +00:00
parent 64836447f2
commit dfd649678c

View file

@ -1,20 +1,21 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#source openrc.sh #source openrc.sh
#export OS_AUTH_TYPE=v3applicationcredential export OS_AUTH_TYPE=v3applicationcredential
#export OS_AUTH_URL=https://auth.cloud.ovh.net/ export OS_AUTH_URL=https://auth.cloud.ovh.net/
#export OS_IDENTITY_API_VERSION=3 export OS_IDENTITY_API_VERSION=3
#export OS_INTERFACE=public export OS_INTERFACE=public
#export OS_REGION_NAME="GRA11" export OS_REGION_NAME="GRA11"
#export OS_APPLICATION_CREDENTIAL_ID= export OS_APPLICATION_CREDENTIAL_ID=
#export OS_APPLICATION_CREDENTIAL_SECRET= export OS_APPLICATION_CREDENTIAL_SECRET=
export PROJECT_ID=
#Daily Retention (Nb of months) #Daily Retention (Nb of months)
export DAILY_RETENTION=7 export DAILY_RETENTION=20
#Monthly Retention (Nb of months) #Monthly Retention (Nb of months)
# 0 = disable monthly backup # 0 = disable monthly backup
export MONTHLY_RETENTION=0 export MONTHLY_RETENTION=12
# DAY OF MOUNTH TO EXECUTE MONTHLY BACKUP # DAY OF MOUNTH TO EXECUTE MONTHLY BACKUP
# 01 ... 30 31 # 01 ... 30 31
export DAY_MONTHLY_BACKUP=01 export DAY_MONTHLY_BACKUP=01
@ -29,6 +30,9 @@ export DAY_OF_YEARLY_BACKUP=01
# 01:january... 12:December # 01:january... 12:December
export MONTH_OF_YEARLY_BACKUP=01 export MONTH_OF_YEARLY_BACKUP=01
# Number of backup instances to keep
export MAX_KEEP_BACKUP_INSTANCES=100
#Set TimeZone #Set TimeZone
export TZ=Europe/Paris export TZ=Europe/Paris
@ -166,7 +170,7 @@ function backup(){
_info_action " ------> [Instance : ${SERVER}] ---> Launching the Snapshot of the instance ${SERVER} to ${BCK_SERVER}" _info_action " ------> [Instance : ${SERVER}] ---> Launching the Snapshot of the instance ${SERVER} to ${BCK_SERVER}"
BCK_INSTANCES_LIST+=(${BCK_SERVER}) BCK_INSTANCES_LIST+=(${BCK_SERVER})
${OPENSTACK} server backup create --name ${BCK_SERVER} ${SERVER} ${OPENSTACK} server backup create --rotate ${MAX_KEEP_BACKUP_INSTANCES} --name ${BCK_SERVER} ${SERVER}
_info_blue " ------> [Instance : ${SERVER}] === === End of the backup === ===" _info_blue " ------> [Instance : ${SERVER}] === === End of the backup === ==="
done done
@ -179,7 +183,7 @@ function check_backup(){
_info "================================================================================" _info "================================================================================"
MAXIMUM_TIMESTAMP=`date -d '+'${CHECK_BACKUP_DELAY}' seconds' '+%s'` MAXIMUM_TIMESTAMP=`date -d '+'${CHECK_BACKUP_DELAY}' seconds' '+%s'`
echo "" echo ""
_info " => Checking the backup of volumes" _info " => Checking the backup of volumes"
for BCK_VOLUME in "${BCK_VOLUMES_LIST[@]}" for BCK_VOLUME in "${BCK_VOLUMES_LIST[@]}"
@ -228,7 +232,7 @@ function manage_retention(){
_info "================================================================================" _info "================================================================================"
_info " - Manage Backup Retention" _info " - Manage Backup Retention"
_info "================================================================================" _info "================================================================================"
echo "" echo ""
_info " ====> Manage Retention for Backup Volumes <====" _info " ====> Manage Retention for Backup Volumes <===="
ALL_BCK_VOLUMES=$(${OPENSTACK} volume backup list -f json) ALL_BCK_VOLUMES=$(${OPENSTACK} volume backup list -f json)
@ -349,7 +353,7 @@ function manage_retention(){
function job_details(){ function job_details(){
_info_blue "#######################################################################################" _info_blue "#######################################################################################"
_info_blue "Starting Backup Job " _info_blue "Starting Backup Job "
PJT_DESC=$(${OPENSTACK} project show ${OS_TENANT_ID} -f json | ${JQ} -r '.description') PJT_DESC=$(${OPENSTACK} project show ${PROJECT_ID} -f json | ${JQ} -r '.description')
_info_blue " ---> Project Description : ${PJT_DESC}" _info_blue " ---> Project Description : ${PJT_DESC}"
_info_blue " ---> Region : ${OS_REGION_NAME}" _info_blue " ---> Region : ${OS_REGION_NAME}"
@ -369,7 +373,7 @@ function job_details(){
else else
_info_blue " --> Monthly Retention : Disabled" _info_blue " --> Monthly Retention : Disabled"
fi fi
if [ "${YEARLY_RETENTION}" != "0" ]; then if [ "${YEARLY_RETENTION}" != "0" ]; then
_info_blue " --> Yearly Retention : ${YEARLY_RETENTION} Year(s)" _info_blue " --> Yearly Retention : ${YEARLY_RETENTION} Year(s)"
else else
@ -402,7 +406,6 @@ function _warning(){
function main() { function main() {
job_details job_details
exit
check_prerequistes check_prerequistes
backup backup
check_backup check_backup
@ -411,4 +414,4 @@ function main() {
main "$@" main "$@"
exit ${EXIT} exit ${EXIT}