Skip to content

Instantly share code, notes, and snippets.

@szhu
Last active July 11, 2025 14:42
Show Gist options
  • Select an option

  • Save szhu/0c8b1c19eea2830563b804ba70a48f1a to your computer and use it in GitHub Desktop.

Select an option

Save szhu/0c8b1c19eea2830563b804ba70a48f1a to your computer and use it in GitHub Desktop.
#!/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