ci: бэкап сервера по кнопке
This commit is contained in:
+15
@@ -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
|
||||||
@@ -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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user