Created
October 23, 2024 19:44
-
-
Save bgulla/0c15bf492b908a0d249fc151c63d13de to your computer and use it in GitHub Desktop.
Velero Makefile Helper Outer 5000
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
# Define some variables | |
NAMESPACE ?= default | |
BACKUP_NAME ?= backup-$(shell date +%Y%m%d%H%M%S) | |
RESTORE_NAME ?= restore-$(shell date +%Y%m%d%H%M%S) | |
SCHEDULE_NAME ?= daily-backup | |
BUCKET ?= velero-backup-bucket | |
POLL_INTERVAL ?= 5 # Check backup status every 5 seconds | |
# Help message | |
.PHONY: help | |
help: | |
@echo "Velero Makefile" | |
@echo "Usage:" | |
@echo " make backup - Create a Velero backup and watch the status" | |
@echo " make restore - Restore from the latest Velero backup and watch the status" | |
@echo " make backup-list - List all Velero backups" | |
@echo " make restore-list - List all Velero restores" | |
@echo " make backup-delete - Delete a Velero backup" | |
@echo " make restore-delete - Delete a Velero restore" | |
@echo " make schedule-create - Create a scheduled backup" | |
@echo " make schedule-delete - Delete a backup schedule" | |
# Create a backup and watch status | |
.PHONY: backup | |
backup: | |
@echo "Creating Velero backup: $(BACKUP_NAME)" | |
velero backup create $(BACKUP_NAME) --include-namespaces $(NAMESPACE) # --resource-policies-configmap velero-resource-policy-cm | |
@echo "Watching backup status: $(BACKUP_NAME)" | |
@while true; do \ | |
status=$$(velero backup get $(BACKUP_NAME) -o json | jq -r '.status.phase'); \ | |
echo "Current status: $$status"; \ | |
if [ "$$status" = "Completed" ] || [ "$$status" = "Failed" ]; then \ | |
break; \ | |
fi; \ | |
sleep $(POLL_INTERVAL); \ | |
done | |
# Restore from the latest backup and watch status | |
.PHONY: restore | |
restore: | |
@echo "Restoring from the latest Velero backup" | |
LATEST_BACKUP=$(shell velero backup get -o json | jq -r '.[0].metadata.name'); \ | |
echo "Restoring from backup: $$LATEST_BACKUP"; \ | |
velero restore create $(RESTORE_NAME) --from-backup $$LATEST_BACKUP; \ | |
while true; do \ | |
status=$$(velero restore get $(RESTORE_NAME) -o json | jq -r '.status.phase'); \ | |
echo "Current restore status: $$status"; \ | |
if [ "$$status" = "Completed" ] || [ "$$status" = "Failed" ]; then \ | |
break; \ | |
fi; \ | |
sleep $(POLL_INTERVAL); \ | |
done | |
# List all backups | |
.PHONY: backup-list | |
backup-list: | |
@echo "Listing all Velero backups" | |
velero backup get | |
# List all restores | |
.PHONY: restore-list | |
restore-list: | |
@echo "Listing all Velero restores" | |
velero restore get | |
# Delete a specific backup | |
.PHONY: backup-delete | |
backup-delete: | |
@echo "Deleting Velero backup: $(BACKUP_NAME)" | |
velero backup delete $(BACKUP_NAME) | |
# Delete a specific restore | |
.PHONY: restore-delete | |
restore-delete: | |
@echo "Deleting Velero restore: $(RESTORE_NAME)" | |
velero restore delete $(RESTORE_NAME) | |
# Create a daily backup schedule | |
.PHONY: schedule-create | |
schedule-create: | |
@echo "Creating a daily backup schedule: $(SCHEDULE_NAME)" | |
velero schedule create $(SCHEDULE_NAME) --schedule "0 2 * * *" --include-namespaces $(NAMESPACE) | |
# Delete the backup schedule | |
.PHONY: schedule-delete | |
schedule-delete: | |
@echo "Deleting backup schedule: $(SCHEDULE_NAME)" | |
velero schedule delete $(SCHEDULE_NAME) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment