From 342754acb5bc1780a97624721343ead122e47f7f Mon Sep 17 00:00:00 2001 From: Denis Khristolyubov Date: Sun, 13 Sep 2026 00:52:13 +0200 Subject: [PATCH] =?UTF-8?q?ci:=20=D0=B1=D1=8D=D0=BA=D0=B0=D0=BF=20=D1=81?= =?UTF-8?q?=D0=B5=D1=80=D0=B2=D0=B5=D1=80=D0=B0=20=D0=BF=D0=BE=20=D0=BA?= =?UTF-8?q?=D0=BD=D0=BE=D0=BF=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backup.bat | 15 +++++++++++++++ ci/pull-backup.ps1 | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 backup.bat create mode 100644 ci/pull-backup.ps1 diff --git a/backup.bat b/backup.bat new file mode 100644 index 0000000..12cc5b8 --- /dev/null +++ b/backup.bat @@ -0,0 +1,15 @@ +@echo off +chcp 65001 >nul +title RECADA backup +echo. +echo Tyanu svezhiy dump Gitea s servera EX44... +echo. +powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0ci\pull-backup.ps1" +echo. +if errorlevel 1 ( + echo NE POLUCHILOS. Proverj: vklyuchen li tunnel WireGuard? +) else ( + echo Gotovo. Papka: C:\Backups\recada +) +echo. +pause diff --git a/ci/pull-backup.ps1 b/ci/pull-backup.ps1 new file mode 100644 index 0000000..406f773 --- /dev/null +++ b/ci/pull-backup.ps1 @@ -0,0 +1,46 @@ +# pull-backup.ps1 +# Pulls the latest Gitea dump from the EX44 server to this computer. +# Run by Windows Task Scheduler. Requires the WireGuard tunnel to be up. +# ASCII only on purpose: PowerShell 5.1 reads .ps1 as ANSI and mangles UTF-8. + +$ErrorActionPreference = 'Stop' + +$Server = 'root@10.10.0.1' +$Dest = 'C:\Backups\recada' +$Keep = 14 # how many dumps to keep locally + +New-Item -ItemType Directory -Force -Path $Dest | Out-Null +$log = Join-Path $Dest 'backup.log' + +function Say([string]$msg) { + $line = "{0} {1}" -f (Get-Date -Format 'yyyy-MM-dd HH:mm:ss'), $msg + Write-Host $line + Add-Content -Path $log -Value $line +} + +try { + $latest = (ssh -o BatchMode=yes -o ConnectTimeout=10 $Server ` + "ls -1t /srv/backup/gitea-*.zip 2>/dev/null | head -1") + if ($latest) { $latest = $latest.Trim() } + if (-not $latest) { throw 'no dumps found on server' } + + $name = ($latest -split '/')[-1] + $target = Join-Path $Dest $name + + if (Test-Path $target) { + Say "already here: $name" + } else { + scp -o BatchMode=yes "${Server}:$latest" $target + $size = [math]::Round((Get-Item $target).Length / 1MB, 1) + Say "pulled: $name ($size MB)" + } + + Get-ChildItem $Dest -Filter 'gitea-*.zip' | + Sort-Object LastWriteTime -Descending | + Select-Object -Skip $Keep | + ForEach-Object { Remove-Item $_.FullName -Force; Say "pruned: $($_.Name)" } +} +catch { + Say "ERROR: $($_.Exception.Message)" + exit 1 +}