35 lines
651 B
Bash
35 lines
651 B
Bash
#!/bin/bash
|
|
# Restore a git mirror backup into a target repository.
|
|
# Works on Linux and macOS.
|
|
|
|
set -euo pipefail
|
|
|
|
if [ $# -lt 2 ]; then
|
|
echo "Usage: $0 <backup.zip> <target-repo-url>"
|
|
exit 1
|
|
fi
|
|
|
|
ZIP="$1"
|
|
TARGET="$2"
|
|
WORK_DIR=".tmp_restore_mirror"
|
|
|
|
if [ ! -f "$ZIP" ]; then
|
|
echo "Error: file not found: $ZIP"
|
|
exit 1
|
|
fi
|
|
|
|
# Cleanup on exit
|
|
cleanup() { rm -rf "$WORK_DIR"; }
|
|
trap cleanup EXIT
|
|
|
|
echo "[1/3] Extracting $ZIP ..."
|
|
mkdir -p "$WORK_DIR"
|
|
unzip -q "$ZIP" -d "$WORK_DIR"
|
|
|
|
echo "[2/3] Pushing all refs to $TARGET ..."
|
|
cd "$WORK_DIR"
|
|
git remote set-url origin "$TARGET"
|
|
git push --mirror
|
|
|
|
echo "[3/3] Done. Repository restored at $TARGET"
|