Files

44 lines
1.7 KiB
PowerShell
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 代码库镜像同步脚本(GitHub 外部仓库 -> git.vanusys.com 内部镜像)
# 用法:
# 1. 按下方 $Mirrors 表登记镜像(镜像工作区目录 + 内部镜像地址)
# 2. 首次:git clone --mirror <上游> <工作区目录>
# 3. 之后:本脚本 fetch 上游并 push --mirror 到内部
# 建议配合 Windows 任务计划程序每日/每周运行;也可移植到香港服务器 cron。
# 注意:统一使用 openssl TLS 后端,规避 schannel 在本机受限环境的问题。
$ErrorActionPreference = 'Stop'
# 镜像登记表:Name -> @{ Upstream = 上游地址; Mirror = 内部镜像地址; Workspace = 本地裸仓库路径 }
$Mirrors = @{
'astryx' = @{
Upstream = 'https://github.com/facebook/astryx'
Mirror = 'https://git.vanusys.com/VanuSystems/facebook-astryx.git'
Workspace = 'C:\Users\VanuSystems-Mu\Documents\AI\服务器运维\mirrors\astryx.git'
}
}
$GlobalSsl = @('-c', 'http.sslBackend=openssl')
foreach ($name in $Mirrors.Keys | Sort-Object) {
$m = $Mirrors[$name]
Write-Host "=== 同步 $name ==="
if (-not (Test-Path $m.Workspace)) {
Write-Warning "镜像工作区不存在: $($m.Workspace),跳过(请先 git clone --mirror)"
continue
}
Push-Location $m.Workspace
try {
Write-Host "[1/2] 从上游 fetch ..."
& git @GlobalSsl fetch --prune origin '+refs/*:refs/*'
if ($LASTEXITCODE -ne 0) { throw "fetch 失败: $name" }
Write-Host "[2/2] push 到内部镜像 ..."
& git @GlobalSsl push --mirror $m.Mirror
if ($LASTEXITCODE -ne 0) { throw "push 失败: $name" }
Write-Host "OK: $name"
}
finally {
Pop-Location
}
}
Write-Host "全部镜像同步完成。"