Last active
May 12, 2023 04:04
-
-
Save recursivecodes/747585feb9298d0b48b2a8d4f25e9298 to your computer and use it in GitHub Desktop.
backup.sh
This file contains 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 | |
source ~/.zshrc | |
PROFILE_NAME=DEFAULT | |
BACKUP_NAME=[your_manual_backup_name] | |
TMP_BACKUP_NAME=$(date +%Y-%m-%d_%H-%M-%S) | |
echo "Running at ${TMP_BACKUP_NAME}." | |
echo "Getting previous backup..." | |
OUTPUT=$(oci bv boot-volume-backup list --display-name ${BACKUP_NAME} --lifecycle-state AVAILABLE --query "data [0].{bootVolumeId:\"boot-volume-id\",id:id}" --raw-output --profile ${PROFILE_NAME}) | |
LAST_BACKUP_ID=$(echo $OUTPUT | /usr/local/bin/jq -r '.id') | |
BOOT_VOLUME_ID=$(echo $OUTPUT | /usr/local/bin/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
I updated the script for Linux and fixed some errors that occurred. Here it is if somebody needs it: