summaryrefslogtreecommitdiff
path: root/backup_repos.sh
diff options
context:
space:
mode:
authortslil <tslil@posteo.de>2026-08-28 22:01:16 +0100
committertslil <tslil@posteo.de>2026-08-28 22:01:45 +0100
commitef6f9934efd6e67dce5fe6712d1cdae121a24547 (patch)
treefe6b41033032e43f787fa9c8fb3f06d257adfd2d /backup_repos.sh
parentb012345782f415d3704f54d3bd2d22303f00d950 (diff)
backup_repos.sh: small script to backup my reposHEADmaster
Diffstat (limited to 'backup_repos.sh')
-rwxr-xr-xbackup_repos.sh41
1 files changed, 41 insertions, 0 deletions
diff --git a/backup_repos.sh b/backup_repos.sh
new file mode 100755
index 0000000..e34d1ea
--- /dev/null
+++ b/backup_repos.sh
@@ -0,0 +1,41 @@
+#!/usr/bin/env sh
+
+export GIT_TERMINAL_PROMPT=0
+BASE=/mnt/ssd-data/repos/
+
+pick_branch() {
+ git -C "$1" for-each-ref --format='%(refname:short)' 'refs/remotes/origin/*' \
+ | sed 's#^origin/##' \
+ | grep -E '^(main|master|dev)$' \
+ | head -n1
+}
+
+repos=$(2>1 ssh git.l-3.space | awk '/tslil\// {print $2}')
+
+echo Found $repos
+printf "\n\n"
+
+for repo in $repos; do
+ REMOTE="ssh://git.l-3.space/$repo.git"
+ DIR="$BASE/$repo"
+ echo Looking at "$REMOTE" for "$DIR"
+ if [ -d "$DIR/.git" ]; then
+ echo "Syncing existing repo $DIR from $REMOTE ..."
+ if git -C "$DIR" fetch -q origin \
+ && BRANCH="$(pick_branch "$DIR")" && [ -n "$BRANCH" ] \
+ && git -C "$DIR" reset --hard -q "origin/$BRANCH" \
+ && git -C "$DIR" clean -fdxq; then
+ echo "OK: $DIR synced to remote from $BRANCH."
+ else
+ echo "Sync failed, removing $DIR and re-cloning..."
+ rm -rf "$DIR"
+ git clone -q "$REMOTE" "$DIR"
+ echo "OK: $DIR re-cloned from $REMOTE."
+ fi
+ else
+ echo "No repo at $DIR, cloning..."
+ git clone -q "$REMOTE" "$DIR"
+ echo "OK: $DIR cloned from $REMOTE."
+ fi
+ printf "\n\n"
+done