Actualiser Backup_OpenStack_Vms_And_Volumes.sh
This commit is contained in:
parent
0f87d1c896
commit
b6d7ef3788
1 changed files with 52 additions and 17 deletions
|
@ -30,11 +30,16 @@
|
||||||
# 01:january... 12:December
|
# 01:january... 12:December
|
||||||
#export MONTH_OF_YEARLY_BACKUP=01
|
#export MONTH_OF_YEARLY_BACKUP=01
|
||||||
|
|
||||||
# BACKUP_REPLICATE_REGION
|
#### Backup Replication
|
||||||
# "" = disable replication
|
# ENABLE_BACKUP_REPLICATION=0 : disable replication
|
||||||
#export BCK_REPLICATE_REGION=""
|
# ENABLE_BACKUP_REPLICATION=1 : enable replication
|
||||||
#export BCK_RCLONE_SRC_ALIAS=""
|
export ENABLE_BACKUP_REPLICATION=0
|
||||||
#export BCK_RCLONE_DST_ALIAS=""
|
export BCK_REPLICATION_OS_REGION_NAME=${OS_REGION_NAME}
|
||||||
|
export BCK_REPLICATION_OS_APPLICATION_CREDENTIAL_ID=${OS_APPLICATION_CREDENTIAL_ID}
|
||||||
|
export BCK_REPLICATION_OS_APPLICATION_CREDENTIAL_SECRET=${OS_APPLICATION_CREDENTIAL_SECRET}
|
||||||
|
export BCK_REPLICATION_PROJECT_ID=${PROJECT_ID}
|
||||||
|
export BCK_RCLONE_SRC_ALIAS=""
|
||||||
|
export BCK_RCLONE_DST_ALIAS=""
|
||||||
export BCK_REPLICATE_TMP_DIR=/opt/backup/tmp
|
export BCK_REPLICATE_TMP_DIR=/opt/backup/tmp
|
||||||
|
|
||||||
# Number of backup instances to keep
|
# Number of backup instances to keep
|
||||||
|
@ -43,7 +48,11 @@ export MAX_KEEP_BACKUP_INSTANCES=100
|
||||||
#Set TimeZone
|
#Set TimeZone
|
||||||
#export TZ=Europe/Paris
|
#export TZ=Europe/Paris
|
||||||
|
|
||||||
ORIGIN_REGION=${OS_REGION_NAME}
|
ORIGIN_OS_REGION_NAME=${OS_REGION_NAME}
|
||||||
|
ORIGIN_OS_APPLICATION_CREDENTIAL_ID=${OS_APPLICATION_CREDENTIAL_ID}
|
||||||
|
ORIGIN_OS_APPLICATION_CREDENTIAL_SECRET=${OS_APPLICATION_CREDENTIAL_SECRET}
|
||||||
|
ORIGIN_PROJECT_ID=${PROJECT_ID}
|
||||||
|
|
||||||
TODAY=$(date +"%Y-%m-%d_%HH%M")
|
TODAY=$(date +"%Y-%m-%d_%HH%M")
|
||||||
DAY_OF_MONTH=$(date +"%d")
|
DAY_OF_MONTH=$(date +"%d")
|
||||||
MONTH_OF_YEAR=$(date +"%m")
|
MONTH_OF_YEAR=$(date +"%m")
|
||||||
|
@ -207,12 +216,18 @@ function replicate_backup(){
|
||||||
do
|
do
|
||||||
BCK_INSTANCE_TODAY=${BCK_INSTANCE}_${TODAY}
|
BCK_INSTANCE_TODAY=${BCK_INSTANCE}_${TODAY}
|
||||||
|
|
||||||
export OS_REGION_NAME=${ORIGIN_REGION}
|
export OS_REGION_NAME=${ORIGIN_OS_REGION_NAME}
|
||||||
|
export OS_APPLICATION_CREDENTIAL_ID=${ORIGIN_OS_APPLICATION_CREDENTIAL_ID}
|
||||||
|
export OS_APPLICATION_CREDENTIAL_SECRET=${ORIGIN_OS_APPLICATION_CREDENTIAL_SECRET}
|
||||||
|
export PROJECT_ID=${ORIGIN_PROJECT_ID}
|
||||||
_info_action " Local recording backup Instance ${BCK_INSTANCE_TODAY}"
|
_info_action " Local recording backup Instance ${BCK_INSTANCE_TODAY}"
|
||||||
BCK_INSTANCE_ID=$(${OPENSTACK} image show ${BCK_INSTANCE_TODAY} -c id -f value)
|
BCK_INSTANCE_ID=$(${OPENSTACK} image show ${BCK_INSTANCE_TODAY} -c id -f value)
|
||||||
${OPENSTACK} image save --file ${BCK_REPLICATE_TMP_DIR}/${BCK_INSTANCE_TODAY}.qcow ${BCK_INSTANCE_ID}
|
${OPENSTACK} image save --file ${BCK_REPLICATE_TMP_DIR}/${BCK_INSTANCE_TODAY}.qcow ${BCK_INSTANCE_ID}
|
||||||
|
|
||||||
export OS_REGION_NAME=${BCK_REPLICATE_REGION}
|
export OS_REGION_NAME=${BCK_REPLICATION_OS_REGION_NAME}
|
||||||
|
export OS_APPLICATION_CREDENTIAL_ID=${BCK_REPLICATION_OS_APPLICATION_CREDENTIAL_ID}
|
||||||
|
export OS_APPLICATION_CREDENTIAL_SECRET=${BCK_REPLICATION_OS_APPLICATION_CREDENTIAL_SECRET}
|
||||||
|
export PROJECT_ID=${BCK_REPLICATION_PROJECT_ID}
|
||||||
_info_action " Replicating backup Instance ${BCK_INSTANCE_TODAY}"
|
_info_action " Replicating backup Instance ${BCK_INSTANCE_TODAY}"
|
||||||
${OPENSTACK} image create --disk-format qcow2 --container-format bare --file ${BCK_REPLICATE_TMP_DIR}/${BCK_INSTANCE_TODAY}.qcow ${BCK_INSTANCE_TODAY}
|
${OPENSTACK} image create --disk-format qcow2 --container-format bare --file ${BCK_REPLICATE_TMP_DIR}/${BCK_INSTANCE_TODAY}.qcow ${BCK_INSTANCE_TODAY}
|
||||||
|
|
||||||
|
@ -222,7 +237,10 @@ function replicate_backup(){
|
||||||
_info_action " Backup Replication of ${BCK_INSTANCE_TODAY} is OK"
|
_info_action " Backup Replication of ${BCK_INSTANCE_TODAY} is OK"
|
||||||
done
|
done
|
||||||
|
|
||||||
export OS_REGION_NAME=${ORIGIN_REGION}
|
export OS_REGION_NAME=${ORIGIN_OS_REGION_NAME}
|
||||||
|
export OS_APPLICATION_CREDENTIAL_ID=${ORIGIN_OS_APPLICATION_CREDENTIAL_ID}
|
||||||
|
export OS_APPLICATION_CREDENTIAL_SECRET=${ORIGIN_OS_APPLICATION_CREDENTIAL_SECRET}
|
||||||
|
export PROJECT_ID=${ORIGIN_PROJECT_ID}
|
||||||
echo ""
|
echo ""
|
||||||
_info " => Starting Backup Volume Replication"
|
_info " => Starting Backup Volume Replication"
|
||||||
|
|
||||||
|
@ -233,19 +251,28 @@ function replicate_backup(){
|
||||||
do
|
do
|
||||||
BCK_VOLUME_TODAY=${BCK_VOLUME}_${TODAY}
|
BCK_VOLUME_TODAY=${BCK_VOLUME}_${TODAY}
|
||||||
|
|
||||||
export OS_REGION_NAME=${ORIGIN_REGION}
|
export OS_REGION_NAME=${ORIGIN_OS_REGION_NAME}
|
||||||
|
export OS_APPLICATION_CREDENTIAL_ID=${ORIGIN_OS_APPLICATION_CREDENTIAL_ID}
|
||||||
|
export OS_APPLICATION_CREDENTIAL_SECRET=${ORIGIN_OS_APPLICATION_CREDENTIAL_SECRET}
|
||||||
|
export PROJECT_ID=${ORIGIN_PROJECT_ID}
|
||||||
_info_action " Exporting Metadata for backup volume ${BCK_VOLUME_TODAY}"
|
_info_action " Exporting Metadata for backup volume ${BCK_VOLUME_TODAY}"
|
||||||
BCK_VOLUME_ID=$(${OPENSTACK} volume backup list --name ${BCK_VOLUME_TODAY} -c ID -f value)
|
BCK_VOLUME_ID=$(${OPENSTACK} volume backup list --name ${BCK_VOLUME_TODAY} -c ID -f value)
|
||||||
BCK_VOLUME_JSON_EXPORT=$(${OPENSTACK} volume backup record export -f json ${BCK_VOLUME_ID})
|
BCK_VOLUME_JSON_EXPORT=$(${OPENSTACK} volume backup record export -f json ${BCK_VOLUME_ID})
|
||||||
BCK_VOLUME_EXPORT_SVC=$(echo $BCK_VOLUME_JSON_EXPORT | ${JQ} -r '.backup_service')
|
BCK_VOLUME_EXPORT_SVC=$(echo $BCK_VOLUME_JSON_EXPORT | ${JQ} -r '.backup_service')
|
||||||
BCK_VOLUME_EXPORT_URL=$(echo $BCK_VOLUME_JSON_EXPORT | ${JQ} -r '.backup_url')
|
BCK_VOLUME_EXPORT_URL=$(echo $BCK_VOLUME_JSON_EXPORT | ${JQ} -r '.backup_url')
|
||||||
|
|
||||||
export OS_REGION_NAME=${BCK_REPLICATE_REGION}
|
export OS_REGION_NAME=${BCK_REPLICATION_OS_REGION_NAME}
|
||||||
|
export OS_APPLICATION_CREDENTIAL_ID=${BCK_REPLICATION_OS_APPLICATION_CREDENTIAL_ID}
|
||||||
|
export OS_APPLICATION_CREDENTIAL_SECRET=${BCK_REPLICATION_OS_APPLICATION_CREDENTIAL_SECRET}
|
||||||
|
export PROJECT_ID=${BCK_REPLICATION_PROJECT_ID}
|
||||||
_info_action " Importing Metadata for backup volume ${BCK_VOLUME_TODAY}"
|
_info_action " Importing Metadata for backup volume ${BCK_VOLUME_TODAY}"
|
||||||
${OPENSTACK} volume backup record import ${BCK_VOLUME_EXPORT_SVC} ${BCK_VOLUME_EXPORT_URL}
|
${OPENSTACK} volume backup record import ${BCK_VOLUME_EXPORT_SVC} ${BCK_VOLUME_EXPORT_URL}
|
||||||
done
|
done
|
||||||
|
|
||||||
export OS_REGION_NAME=${ORIGIN_REGION}
|
export OS_REGION_NAME=${ORIGIN_OS_REGION_NAME}
|
||||||
|
export OS_APPLICATION_CREDENTIAL_ID=${ORIGIN_OS_APPLICATION_CREDENTIAL_ID}
|
||||||
|
export OS_APPLICATION_CREDENTIAL_SECRET=${ORIGIN_OS_APPLICATION_CREDENTIAL_SECRET}
|
||||||
|
export PROJECT_ID=${ORIGIN_PROJECT_ID}
|
||||||
}
|
}
|
||||||
|
|
||||||
function check_backup(){
|
function check_backup(){
|
||||||
|
@ -484,11 +511,19 @@ function main() {
|
||||||
backup
|
backup
|
||||||
check_backup
|
check_backup
|
||||||
manage_retention
|
manage_retention
|
||||||
if [ -n "$BCK_REPLICATE_REGION" ]; then
|
|
||||||
replicate_backup
|
if [ "$ENABLE_BACKUP_REPLICATION" -eq "1" ]; then
|
||||||
export OS_REGION_NAME=${BCK_REPLICATE_REGION}
|
replicate_backup
|
||||||
manage_retention
|
|
||||||
export OS_REGION_NAME=${ORIGIN_REGION}
|
export OS_REGION_NAME=${BCK_REPLICATION_OS_REGION_NAME}
|
||||||
|
export OS_APPLICATION_CREDENTIAL_ID=${BCK_REPLICATION_OS_APPLICATION_CREDENTIAL_ID}
|
||||||
|
export OS_APPLICATION_CREDENTIAL_SECRET=${BCK_REPLICATION_OS_APPLICATION_CREDENTIAL_SECRET}
|
||||||
|
export PROJECT_ID=${BCK_REPLICATION_PROJECT_ID}
|
||||||
|
manage_retention
|
||||||
|
export OS_REGION_NAME=${ORIGIN_OS_REGION_NAME}
|
||||||
|
export OS_APPLICATION_CREDENTIAL_ID=${ORIGIN_OS_APPLICATION_CREDENTIAL_ID}
|
||||||
|
export OS_APPLICATION_CREDENTIAL_SECRET=${ORIGIN_OS_APPLICATION_CREDENTIAL_SECRET}
|
||||||
|
export PROJECT_ID=${ORIGIN_PROJECT_ID}
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue