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
|
||||
#export MONTH_OF_YEARLY_BACKUP=01
|
||||
|
||||
# BACKUP_REPLICATE_REGION
|
||||
# "" = disable replication
|
||||
#export BCK_REPLICATE_REGION=""
|
||||
#export BCK_RCLONE_SRC_ALIAS=""
|
||||
#export BCK_RCLONE_DST_ALIAS=""
|
||||
#### Backup Replication
|
||||
# ENABLE_BACKUP_REPLICATION=0 : disable replication
|
||||
# ENABLE_BACKUP_REPLICATION=1 : enable replication
|
||||
export ENABLE_BACKUP_REPLICATION=0
|
||||
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
|
||||
|
||||
# Number of backup instances to keep
|
||||
|
@ -43,7 +48,11 @@ export MAX_KEEP_BACKUP_INSTANCES=100
|
|||
#Set TimeZone
|
||||
#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")
|
||||
DAY_OF_MONTH=$(date +"%d")
|
||||
MONTH_OF_YEAR=$(date +"%m")
|
||||
|
@ -207,12 +216,18 @@ function replicate_backup(){
|
|||
do
|
||||
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}"
|
||||
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}
|
||||
|
||||
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}"
|
||||
${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"
|
||||
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 ""
|
||||
_info " => Starting Backup Volume Replication"
|
||||
|
||||
|
@ -233,19 +251,28 @@ function replicate_backup(){
|
|||
do
|
||||
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}"
|
||||
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_EXPORT_SVC=$(echo $BCK_VOLUME_JSON_EXPORT | ${JQ} -r '.backup_service')
|
||||
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}"
|
||||
${OPENSTACK} volume backup record import ${BCK_VOLUME_EXPORT_SVC} ${BCK_VOLUME_EXPORT_URL}
|
||||
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(){
|
||||
|
@ -484,11 +511,19 @@ function main() {
|
|||
backup
|
||||
check_backup
|
||||
manage_retention
|
||||
if [ -n "$BCK_REPLICATE_REGION" ]; then
|
||||
replicate_backup
|
||||
export OS_REGION_NAME=${BCK_REPLICATE_REGION}
|
||||
manage_retention
|
||||
export OS_REGION_NAME=${ORIGIN_REGION}
|
||||
|
||||
if [ "$ENABLE_BACKUP_REPLICATION" -eq "1" ]; then
|
||||
replicate_backup
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue