Harden backup against GitLab soft-deletion and mirror branch protection#3
Closed
SupremeCommanderHedgehog wants to merge 1 commit into
Closed
Harden backup against GitLab soft-deletion and mirror branch protection#3SupremeCommanderHedgehog wants to merge 1 commit into
SupremeCommanderHedgehog wants to merge 1 commit into
Conversation
The scheduled backup fired on time but silently pushed nothing for affected repos, because git push --mirror failed for two independent reasons the log recorded only as "exit 1": 1. Soft-deletion: a project deleted on gitlab.com (Free) lingers in a ~7-day retention, still occupying its path but read-only, so pushes return 403. Get-GitLabProject sees it as existing (HTTP 200, not 404), so the script neither recreates nor restores it and 403-loops every run. 2. Branch protection: GitLab auto-protects the default branch, and push --mirror needs force-updates on active repos (rebased branches, deleted PR refs), which the protected-branch hook rejects. Fix: - Get-GitLabProjectDeletionSchedule reads marked_for_deletion_at (with the deprecated marked_for_deletion_on as fallback) via PSObject so an absent field yields $null under Set-StrictMode; backup.ps1 restores pending-deletion projects and logs a WARN. - Clear-GitLabProtectedBranches strips mirror branch protection before each push (per_page=100; empty-list result filtered for StrictMode). Verified: full backup.ps1 run is 7 succeeded, 0 failed, exit 0; PSScriptAnalyzer clean. Closes #2 Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01AMMuyUCUP5qoeD9wvesThC
Owner
Author
SupremeCommanderHedgehog
added a commit
that referenced
this pull request
Jul 18, 2026
…on (#3) The scheduled backup fired on time but silently pushed nothing for affected repos, because git push --mirror failed for two independent reasons the log recorded only as "exit 1": 1. Soft-deletion: a project deleted on gitlab.com (Free) lingers in a ~7-day retention, still occupying its path but read-only, so pushes return 403. Get-GitLabProject sees it as existing (HTTP 200, not 404), so the script neither recreates nor restores it and 403-loops. 2. Branch protection: GitLab auto-protects the default branch, and push --mirror needs force-updates on active repos (rebased branches, deleted PR refs), which the protected-branch hook rejects. Fix: - Get-GitLabProjectDeletionSchedule reads marked_for_deletion_at (with the deprecated marked_for_deletion_on as fallback) via PSObject so an absent field yields $null under Set-StrictMode; backup.ps1 restores pending-deletion projects and logs a WARN. - Clear-GitLabProtectedBranches strips mirror branch protection before each push (per_page=100; empty-list result filtered for StrictMode). Verified: full backup.ps1 run is 7 succeeded, 0 failed, exit 0; PSScriptAnalyzer clean. Closes #2 Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01AMMuyUCUP5qoeD9wvesThC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the silent backup failures tracked in #2.
Root causes
git push --mirror→403 You are not allowed to push code to this project.Get-GitLabProjectsees it as existing (HTTP 200, not 404), so the script neither recreates nor restores it — it 403-loops every run.push --mirrorneeds force-updates on active repos (rebased branches, deleted PR refs), which the protected-branch hook rejects. Private repos only needed fast-forwards, masking this for weeks.Changes
Get-GitLabProjectDeletionSchedule— readsmarked_for_deletion_at(fallback to deprecatedmarked_for_deletion_on) viaPSObject, so an absent field yields$nullunderSet-StrictModeinstead of throwing.Restore-GitLabProject— restores a pending-deletion project (numeric-id route; the encoded-path form returns 405).Clear-GitLabProtectedBranches— strips mirror branch protection before each push (per_page=100; empty-list result filtered for StrictMode).backup.ps1loop wires these in and logs a WARN on restore.Verification
backup.ps1runs; final: 7 succeeded, 0 failed, exit 0.🤖 Generated with Claude Code