git_infra

Git infra scripts for git.bracken.jp
git clone https://git.bracken.jp/git_infra.git
Log | Files | Refs | LICENSE

commit ae57783d554dc047a8f117b3c116470f3a82096f
parent b4e3793c642da241efc3efdac78ef05ded990827
Author: Chris Bracken <chris@bracken.jp>
Date:   Sat, 28 Aug 2021 18:44:44 -0700

Add backup script

Script to automatically backup all git repos on git.bracken.jp.

Designed to be run periodically via cron job.
Diffstat:
Abackup_git.bracken.jp.sh | 36++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+), 0 deletions(-)

diff --git a/backup_git.bracken.jp.sh b/backup_git.bracken.jp.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +TAG=$1 +RETAIN_COUNT=$2 + +# Check script arguments. +if [ -z "$TAG" -o -z "$RETAIN_COUNT" ]; then + echo "usage: $0 BACKUP_TAG RETAIN_COUNT" + exit 1 +fi + +USER=git +HOST=git.bracken.jp +BACKUP_SRC_DIR="/home/git" +BACKUP_SRC_FILES='*.git git_infra' +BACKUP_OUT_DIR="/volume1/Backups/git.bracken.jp/$TAG" +BACKUP_OUT_FILE="$(date +"%Y-%m-%d_%H.%m").txz" + +# Create the new backup. +echo "[git backup] Backup of $HOST:$BACKUP_SRC_DIR ($TAG) starting" +echo "[git backup] Backing up files: $BACKUP_SRC_FILES" +mkdir -p "$BACKUP_OUT_DIR" +ssh $USER@$HOST \ + tar Jcf - -C "$BACKUP_SRC_DIR" "$BACKUP_SRC_FILES" \ + > "$BACKUP_OUT_DIR/$BACKUP_OUT_FILE" +echo "[git backup] Wrote archive $BACKUP_OUT_DIR/$BACKUP_OUT_FILE" + +# Delete archives past the retain count. +EXPIRED_ARCHIVES="$(find "$BACKUP_OUT_DIR" -maxdepth 1 -type f \ + | sort -r | tail -n +$(($RETAIN_COUNT + 1)))" +for f in $EXPIRED_ARCHIVES; do + echo "[git backup] Deleting expired archive: $f" + rm -f "$f" +done + +echo "[git backup] Backup of $HOST:$BACKUP_SRC_DIR ($TAG) complete"