Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions code-backup/code-backup-gitlab.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ set -euo pipefail
# ----------------------------
# Configuration
# ----------------------------
readonly SCRIPT_DIR
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
readonly SCRIPT_DIR
readonly LOG_DIR="$SCRIPT_DIR/logs"
mkdir -p "$LOG_DIR"

readonly RUN_TS
RUN_TS=$( date +%Y%m%d-%H%M%S )
readonly RUN_TS
readonly LOG_FILE="$LOG_DIR/gh-gl-backup-$RUN_TS.log"
readonly ERROR_LOG="$LOG_DIR/gh-gl-errors-$RUN_TS.log"

Expand Down Expand Up @@ -65,7 +65,7 @@ log() {
local level="$1"; shift
local msg="$*"
local ts; ts="$(date '+%Y-%m-%d %H:%M:%S')"
echo -e "${ts} [${level}] ${msg}" | tee -a "$LOG_FILE"
echo -e "${ts} [${level}] ${msg}" | tee -a "$LOG_FILE" >&2
}

log_info() { log "INFO" "${BLUE}$*${NC}"; }
Expand Down Expand Up @@ -279,7 +279,7 @@ process_repo() {
local effective_clone_url="$clone_url"
if [ "$USE_GITHUB_SSH" != "true" ] && [ -n "${GITHUB_TOKEN:-}" ]; then
# GitHub supports token auth via x-access-token username.
effective_clone_url="${clone_url//https:\/\//https:\/\/x-access-token:${GITHUB_TOKEN}@\/}"
effective_clone_url="${clone_url//https:\/\//https:\/\/x-access-token:${GITHUB_TOKEN}@}"
fi

# Clone/update local mirror
Expand Down
13 changes: 8 additions & 5 deletions code-backup/code-backup-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
set -euo pipefail

# Configuration
readonly SCRIPT_DIR
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
readonly SCRIPT_DIR
readonly LOG_DIR="$SCRIPT_DIR/logs"
readonly RUN_TS
RUN_TS=$(date +%Y%m%d-%H%M%S)
readonly RUN_TS
readonly LOG_FILE="$LOG_DIR/code-backup-$RUN_TS.log"
readonly ERROR_LOG="$LOG_DIR/errors-$RUN_TS.log"

Expand All @@ -25,8 +25,8 @@ GITHUB_USERNAME="${GITHUB_USERNAME:-}"
USE_GITHUB_SSH="${USE_GITHUB_SSH:-false}"

# Backup directory will be created with date format
readonly BACKUP_DATE
BACKUP_DATE=$(date +%m-%d-%y)
readonly BACKUP_DATE
readonly BACKUP_DIR_NAME="Code-Backup_${BACKUP_DATE}"
readonly BACKUP_DIR="$HOME/$BACKUP_DIR_NAME"
readonly PROJECTS_DIR="$BACKUP_DIR"
Expand All @@ -49,7 +49,7 @@ log() {
local message="$*"
local timestamp
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "${timestamp} [${level}] ${message}" | tee -a "$LOG_FILE"
echo -e "${timestamp} [${level}] ${message}" | tee -a "$LOG_FILE" >&2
}

log_info() {
Expand Down Expand Up @@ -197,6 +197,7 @@ get_github_repos() {

local count
count="$(echo "$lines" | wc -l | tr -d ' ')"
echo "$lines"
if [ "$count" -lt "$per_page" ]; then
break
fi
Expand Down Expand Up @@ -264,7 +265,7 @@ clone_repository() {

local effective_clone_url="$repo_url"
if [ "$USE_GITHUB_SSH" != "true" ] && [ -n "${GITHUB_TOKEN:-}" ]; then
effective_clone_url="${repo_url//https:\/\//https:\/\/x-access-token:${GITHUB_TOKEN}@\/}"
effective_clone_url="${repo_url//https:\/\//https:\/\/x-access-token:${GITHUB_TOKEN}@}"
fi

if git clone "$effective_clone_url" "$repo_path" 2>>"$ERROR_LOG"; then
Expand All @@ -285,9 +286,11 @@ clone_repository() {
fi
cd "$original_dir" 2>/dev/null || true
fi
return 0
else
log_error "Failed to clone: $repo_name"
((FAILED_REPOS++))
return 1
fi
}

Expand Down
Loading