Last active
July 11, 2025 14:42
-
-
Save szhu/0c8b1c19eea2830563b804ba70a48f1a to your computer and use it in GitHub Desktop.
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
| #!/bin/bash | |
| set -e | |
| if [[ -z "$1" ]]; then | |
| echo "Usage: $0 backup|backup-and-delete|restore" | |
| exit 1 | |
| fi | |
| CMD=$1 | |
| SELF=$0 | |
| DATA=./repo-archive-data.git | |
| case "$CMD" in | |
| "backup") | |
| git bundle create "$DATA" --all | |
| echo "Backup complete." | |
| ;; | |
| "backup-and-delete") | |
| git bundle create "$DATA" --all | |
| echo "Backup complete. Deleting local repository..." | |
| rm -rf .git | |
| find . -mindepth 1 -maxdepth 1 ! -name "$(basename "$SELF")" ! -name "$(basename "$DATA")" -exec rm -rf {} + | |
| echo "Local repository deleted." | |
| ;; | |
| "restore") | |
| git init | |
| git fetch "$DATA" | |
| git checkout FETCH_HEAD || git reset FETCH_HEAD | |
| echo "Restore complete." | |
| ;; | |
| *) | |
| echo "Usage: $0 backup|backup-and-delete|restore" | |
| exit 1 | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment