-
-
Save 0cool-f/27745b5c6d84b548d630eb8b57f4eab7 to your computer and use it in GitHub Desktop.
backup.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| PROFILE_NAME=DEFAULT # <- profile's settings to use from ~/.oci/config | |
| BACKUP_NAME=<INSERT_BAKUP_DISPLAY_NAME_HERE> # <- display name of backup manually started | |
| TMP_BACKUP_NAME=$(date +%Y-%m-%d_%H-%M-%S) | |
| echo "Running at ${TMP_BACKUP_NAME}." | |
| echo "Getting previous backup..." | |
| OCI_TENANCY_ID=$(oci iam compartment list | jq -r '.data[0]."compartment-id"' --raw-output) | |
| OUTPUT=$(oci bv boot-volume-backup list --display-name ${BACKUP_NAME} --compartment-id ${OCI_TENANCY_ID} --lifecycle-state AVAILABLE --query 'data[0].{bootVolumeId:"boot-volume-id",id:id}' --raw-output --profile ${PROFILE_NAME}) | |
| LAST_BACKUP_ID=$(echo $OUTPUT | jq -r '.id') | |
| BOOT_VOLUME_ID=$(echo $OUTPUT | jq -r '.bootVolumeId') | |
| echo "Last backup id: $LAST_BACKUP_ID" | |
| echo "Boot volume id: $BOOT_VOLUME_ID" | |
| echo "Creating new backup..." | |
| NEW_BACKUP_ID=$(oci bv boot-volume-backup create --boot-volume-id ${BOOT_VOLUME_ID} --type FULL --display-name ${TMP_BACKUP_NAME} --wait-for-state AVAILABLE --query "data.id" --raw-output --profile ${PROFILE_NAME}) | |
| if [ -z "$NEW_BACKUP_ID" ] | |
| then | |
| echo "New backup creation failed...Exiting script!"; exit | |
| else | |
| echo "New backup id: $NEW_BACKUP_ID" | |
| fi | |
| echo "Deleting old backup..." | |
| DELETED_BACKUP=$(oci bv boot-volume-backup delete --force --boot-volume-backup-id ${LAST_BACKUP_ID} --wait-for-state TERMINATED --profile ${PROFILE_NAME}) | |
| echo "Renaming temp backup..." | |
| RENAMED_BACKUP=$(oci bv boot-volume-backup update --boot-volume-backup-id ${NEW_BACKUP_ID} --display-name ${BACKUP_NAME} --profile ${PROFILE_NAME}) | |
| echo "Backup process complete! Goodbye!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment