Initial commit
This commit is contained in:
commit
77d35ff965
51 changed files with 5591 additions and 0 deletions
93
Pages/Setup/Database.cshtml
Normal file
93
Pages/Setup/Database.cshtml
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
@page
|
||||
@model PlanTempusAdmin.Pages.Setup.DatabaseModel
|
||||
@{
|
||||
ViewData["Title"] = "Database Schema";
|
||||
}
|
||||
|
||||
<div class="page-header">
|
||||
<h1 class="page-title">Database Schema</h1>
|
||||
<p class="page-subtitle">PostgreSQL schema til backup logs</p>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
backup-logs.sql
|
||||
<button onclick="copyScript('sql-schema')" style="float: right; background: var(--accent); color: var(--background); border: none; padding: 4px 12px; cursor: pointer; font-size: 11px;">
|
||||
Kopier
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<pre id="sql-schema" style="max-height: 600px; overflow: auto;"><code class="language-sql">@Model.SqlSchema</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card mt-2">
|
||||
<div class="card-header">Database Bruger Setup</div>
|
||||
<div class="card-body">
|
||||
<p>Opret en dedikeret bruger til backup scriptet:</p>
|
||||
<pre id="user-setup"><code class="language-sql">-- Opret bruger til backup script
|
||||
CREATE USER backup_writer WITH PASSWORD 'your_secure_password_here';
|
||||
|
||||
-- Giv rettigheder
|
||||
GRANT CONNECT ON DATABASE plantempus TO backup_writer;
|
||||
GRANT USAGE ON SCHEMA public TO backup_writer;
|
||||
GRANT INSERT, UPDATE ON backup_logs TO backup_writer;
|
||||
GRANT USAGE, SELECT ON SEQUENCE backup_logs_id_seq TO backup_writer;
|
||||
|
||||
-- Giv læseadgang (brug din eksisterende app-bruger)
|
||||
-- GRANT SELECT ON backup_logs TO your_app_user;
|
||||
-- GRANT SELECT ON backup_repository_summary TO your_app_user;</code></pre>
|
||||
<button onclick="copyScript('user-setup')" style="background: var(--accent); color: var(--background); border: none; padding: 4px 12px; cursor: pointer; font-size: 11px; margin-top: 8px;">
|
||||
Kopier bruger setup
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card mt-2">
|
||||
<div class="card-header">Tabel Struktur</div>
|
||||
<div class="card-body">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Kolonne</th>
|
||||
<th>Type</th>
|
||||
<th>Beskrivelse</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr><td><code>id</code></td><td>SERIAL</td><td>Primary key</td></tr>
|
||||
<tr><td><code>started_at</code></td><td>TIMESTAMP</td><td>Backup start tidspunkt</td></tr>
|
||||
<tr><td><code>completed_at</code></td><td>TIMESTAMP</td><td>Backup slut tidspunkt</td></tr>
|
||||
<tr><td><code>duration_ms</code></td><td>INTEGER</td><td>Varighed i millisekunder</td></tr>
|
||||
<tr><td><code>backup_type</code></td><td>VARCHAR(50)</td><td>'forgejo_repos', 'postgres_db', etc.</td></tr>
|
||||
<tr><td><code>source_name</code></td><td>VARCHAR(255)</td><td>Repository eller database navn</td></tr>
|
||||
<tr><td><code>source_path</code></td><td>VARCHAR(500)</td><td>Fuld sti på serveren</td></tr>
|
||||
<tr><td><code>destination</code></td><td>VARCHAR(50)</td><td>'azure_blob', 's3', 'local', 'sftp'</td></tr>
|
||||
<tr><td><code>remote_path</code></td><td>VARCHAR(500)</td><td>Sti på destination</td></tr>
|
||||
<tr><td><code>status</code></td><td>VARCHAR(20)</td><td>'running', 'success', 'failed', 'partial'</td></tr>
|
||||
<tr><td><code>size_bytes</code></td><td>BIGINT</td><td>Backup størrelse</td></tr>
|
||||
<tr><td><code>file_count</code></td><td>INTEGER</td><td>Antal filer i backup</td></tr>
|
||||
<tr><td><code>error_message</code></td><td>TEXT</td><td>Fejlbesked hvis fejlet</td></tr>
|
||||
<tr><td><code>error_code</code></td><td>VARCHAR(50)</td><td>Fejlkode</td></tr>
|
||||
<tr><td><code>retry_count</code></td><td>INTEGER</td><td>Antal forsøg</td></tr>
|
||||
<tr><td><code>hostname</code></td><td>VARCHAR(100)</td><td>Server hostname</td></tr>
|
||||
<tr><td><code>script_version</code></td><td>VARCHAR(20)</td><td>Script version</td></tr>
|
||||
<tr><td><code>checksum</code></td><td>VARCHAR(64)</td><td>SHA256 checksum</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
function copyScript(elementId) {
|
||||
const element = document.getElementById(elementId);
|
||||
const text = element.textContent || element.innerText;
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
alert('Kopieret til udklipsholder!');
|
||||
}).catch(err => {
|
||||
console.error('Kunne ikke kopiere:', err);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
}
|
||||
28
Pages/Setup/Database.cshtml.cs
Normal file
28
Pages/Setup/Database.cshtml.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace PlanTempusAdmin.Pages.Setup;
|
||||
|
||||
public class DatabaseModel : PageModel
|
||||
{
|
||||
private readonly IWebHostEnvironment _environment;
|
||||
|
||||
public string SqlSchema { get; set; } = string.Empty;
|
||||
|
||||
public DatabaseModel(IWebHostEnvironment environment)
|
||||
{
|
||||
_environment = environment;
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
var schemaPath = Path.Combine(_environment.ContentRootPath, "Scripts", "backup-logs.sql");
|
||||
if (System.IO.File.Exists(schemaPath))
|
||||
{
|
||||
SqlSchema = System.IO.File.ReadAllText(schemaPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
SqlSchema = "-- Schema not found at: " + schemaPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
54
Pages/Setup/Index.cshtml
Normal file
54
Pages/Setup/Index.cshtml
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
@page
|
||||
@model PlanTempusAdmin.Pages.Setup.IndexModel
|
||||
@{
|
||||
ViewData["Title"] = "Setup";
|
||||
}
|
||||
|
||||
<div class="page-header">
|
||||
<h1 class="page-title">Setup</h1>
|
||||
<p class="page-subtitle">Scripts og konfiguration til servere</p>
|
||||
</div>
|
||||
|
||||
<div class="status-grid">
|
||||
<a href="/Setup/Scripts" class="status-item" style="text-decoration: none; color: inherit;">
|
||||
<div class="status-label">Scripts</div>
|
||||
<div class="status-value">Bash</div>
|
||||
<p style="margin-top: 8px; font-size: 11px; color: var(--foreground);">Backup scripts til Ubuntu servere</p>
|
||||
</a>
|
||||
<a href="/Setup/Database" class="status-item" style="text-decoration: none; color: inherit;">
|
||||
<div class="status-label">Database</div>
|
||||
<div class="status-value">SQL</div>
|
||||
<p style="margin-top: 8px; font-size: 11px; color: var(--foreground);">PostgreSQL schema og migrations</p>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="card mt-2">
|
||||
<div class="card-header">Hurtig Guide</div>
|
||||
<div class="card-body">
|
||||
<h3 style="margin-bottom: 12px;">1. Database Setup</h3>
|
||||
<p>Kør SQL scriptet fra <a href="/Setup/Database">Database</a> siden på din PostgreSQL server.</p>
|
||||
|
||||
<h3 style="margin: 16px 0 12px;">2. Azure CLI Setup</h3>
|
||||
<p>Installer Azure CLI på serveren:</p>
|
||||
<pre><code>curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
|
||||
az --version</code></pre>
|
||||
|
||||
<h3 style="margin: 16px 0 12px;">3. Backup Script</h3>
|
||||
<p>Download scriptet fra <a href="/Setup/Scripts">Scripts</a> siden og placer det på serveren.</p>
|
||||
<pre><code># Placer script
|
||||
sudo mkdir -p /opt/backup
|
||||
sudo cp forgejo-backup.sh /opt/backup/
|
||||
sudo chmod +x /opt/backup/forgejo-backup.sh
|
||||
|
||||
# Opret .env fil med konfiguration
|
||||
sudo nano /opt/backup/.env</code></pre>
|
||||
|
||||
<h3 style="margin: 16px 0 12px;">4. Cron Job</h3>
|
||||
<p>Tilføj daglig backup via cron:</p>
|
||||
<pre><code># Rediger crontab
|
||||
sudo crontab -e
|
||||
|
||||
# Tilføj linje (kører kl. 02:00 hver nat)
|
||||
0 2 * * * /opt/backup/forgejo-backup.sh >> /var/log/forgejo-backup.log 2>&1</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
10
Pages/Setup/Index.cshtml.cs
Normal file
10
Pages/Setup/Index.cshtml.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace PlanTempusAdmin.Pages.Setup;
|
||||
|
||||
public class IndexModel : PageModel
|
||||
{
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
}
|
||||
107
Pages/Setup/Scripts.cshtml
Normal file
107
Pages/Setup/Scripts.cshtml
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
@page
|
||||
@model PlanTempusAdmin.Pages.Setup.ScriptsModel
|
||||
@{
|
||||
ViewData["Title"] = "Backup Scripts";
|
||||
}
|
||||
|
||||
<div class="page-header">
|
||||
<h1 class="page-title">Backup Scripts</h1>
|
||||
<p class="page-subtitle">Bash scripts til Forgejo repository backup</p>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
forgejo-backup.sh
|
||||
<button onclick="copyScript('bash-script')" style="float: right; background: var(--accent); color: var(--background); border: none; padding: 4px 12px; cursor: pointer; font-size: 11px;">
|
||||
Kopier
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<pre id="bash-script" style="max-height: 600px; overflow: auto;"><code class="language-bash">@Model.BashScript</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card mt-2">
|
||||
<div class="card-header">Environment Konfiguration (.env)</div>
|
||||
<div class="card-body">
|
||||
<pre id="env-config"><code class="language-bash"># Forgejo Repository Backup Configuration
|
||||
|
||||
# Sti til Forgejo repositories
|
||||
FORGEJO_REPO_PATH=/var/lib/forgejo/data/forgejo-repositories
|
||||
|
||||
# Midlertidig mappe til backup filer
|
||||
BACKUP_TEMP_DIR=/tmp/forgejo-backups
|
||||
|
||||
# PostgreSQL database konfiguration
|
||||
BACKUP_DB_HOST=192.168.1.43
|
||||
BACKUP_DB_PORT=5432
|
||||
BACKUP_DB_NAME=ptadmin
|
||||
BACKUP_DB_USER=plantempus_app
|
||||
BACKUP_DB_PASSWORD=your_secure_password_here
|
||||
|
||||
# Azure Blob Storage konfiguration
|
||||
AZURE_STORAGE_ACCOUNT=storageptadmin
|
||||
AZURE_STORAGE_KEY=your_storage_key_here
|
||||
AZURE_STORAGE_CONTAINER=backups
|
||||
AZURE_STORAGE_PATH=forgejo
|
||||
|
||||
# Antal dage backup gemmes
|
||||
BACKUP_RETENTION_DAYS=30</code></pre>
|
||||
<button onclick="copyScript('env-config')" style="background: var(--accent); color: var(--background); border: none; padding: 4px 12px; cursor: pointer; font-size: 11px; margin-top: 8px;">
|
||||
Kopier .env
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card mt-2">
|
||||
<div class="card-header">Cron Job Setup</div>
|
||||
<div class="card-body">
|
||||
<p>Tilføj følgende linje til crontab (<code>sudo crontab -e</code>):</p>
|
||||
<pre id="cron-config"><code># Kører backup hver dag kl. 02:00
|
||||
0 2 * * * /opt/backup/forgejo-backup.sh >> /var/log/forgejo-backup.log 2>&1</code></pre>
|
||||
<button onclick="copyScript('cron-config')" style="background: var(--accent); color: var(--background); border: none; padding: 4px 12px; cursor: pointer; font-size: 11px; margin-top: 8px;">
|
||||
Kopier cron
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card mt-2">
|
||||
<div class="card-header">Azure CLI Setup</div>
|
||||
<div class="card-body">
|
||||
<p>Installer Azure CLI på serveren:</p>
|
||||
<pre><code class="language-bash"># Installer Azure CLI (Ubuntu/Debian)
|
||||
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
|
||||
|
||||
# Verificer installation
|
||||
az --version
|
||||
|
||||
# Test forbindelse til storage account
|
||||
az storage container list \
|
||||
--account-name storageptadmin \
|
||||
--account-key "YOUR_KEY_HERE" \
|
||||
--output table
|
||||
|
||||
# Test upload
|
||||
echo "test" > /tmp/test.txt
|
||||
az storage blob upload \
|
||||
--account-name storageptadmin \
|
||||
--account-key "YOUR_KEY_HERE" \
|
||||
--container-name backups \
|
||||
--file /tmp/test.txt \
|
||||
--name test/test.txt</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
function copyScript(elementId) {
|
||||
const element = document.getElementById(elementId);
|
||||
const text = element.textContent || element.innerText;
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
alert('Kopieret til udklipsholder!');
|
||||
}).catch(err => {
|
||||
console.error('Kunne ikke kopiere:', err);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
}
|
||||
28
Pages/Setup/Scripts.cshtml.cs
Normal file
28
Pages/Setup/Scripts.cshtml.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace PlanTempusAdmin.Pages.Setup;
|
||||
|
||||
public class ScriptsModel : PageModel
|
||||
{
|
||||
private readonly IWebHostEnvironment _environment;
|
||||
|
||||
public string BashScript { get; set; } = string.Empty;
|
||||
|
||||
public ScriptsModel(IWebHostEnvironment environment)
|
||||
{
|
||||
_environment = environment;
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
var scriptPath = Path.Combine(_environment.ContentRootPath, "Scripts", "forgejo-backup.sh");
|
||||
if (System.IO.File.Exists(scriptPath))
|
||||
{
|
||||
BashScript = System.IO.File.ReadAllText(scriptPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
BashScript = "# Script not found at: " + scriptPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue