diff --git a/.gitignore b/.gitignore index 4fd6fcc..ced1fbc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,40 +1,40 @@ -# Gitea data directory -data/ - -# Database files -*.db -*.sqlite - -# Log files -*.log - -# Environment files -.env - -# System files -.DS_Store -Thumbs.db - -# Docker volumes -volumes/ - -# Gitea directories -gitea/* -!gitea/ssl/ -!gitea/conf/ - -# SSL certificates (should not be in version control) -gitea/ssl/*.pem -gitea/ssl/*.key -gitea/ssl/*.crt - -# Gitea user data and logs -gitea/gitea/* -gitea/git/* -gitea/ssh/* -gitea/data/* - -# Temporary files -*.tmp -*.temp -*~ +# Gitea data directory +data/ + +# Database files +*.db +*.sqlite + +# Log files +*.log + +# Environment files +.env + +# System files +.DS_Store +Thumbs.db + +# Docker volumes +volumes/ + +# Gitea directories +gitea/* +!gitea/ssl/ +!gitea/conf/ + +# SSL certificates (should not be in version control) +gitea/ssl/*.pem +gitea/ssl/*.key +gitea/ssl/*.crt + +# Gitea user data and logs +gitea/gitea/* +gitea/git/* +gitea/ssh/* +gitea/data/* + +# Temporary files +*.tmp +*.temp +*~ diff --git a/BACKUP-README.md b/BACKUP-README.md index e18fcbe..618b1a6 100644 --- a/BACKUP-README.md +++ b/BACKUP-README.md @@ -1,73 +1,73 @@ -# Gitea Backup Strategy - -This document outlines the backup strategy for your Gitea installation, focusing on ensuring your database is always backed up in at least one place. - -## Backup Methods - -This setup provides two complementary backup methods: - -### 1. PostgreSQL Database Dumps - -Database dumps are SQL files containing all your database data. These are the most reliable way to back up a PostgreSQL database. - -- **Script**: `backup-gitea-db.ps1` -- **Output**: SQL dumps in the `backups` directory, compressed as ZIP files -- **Retention**: Keeps the last 10 backups by default - -### 2. Docker Volume Backups - -This method backs up the entire PostgreSQL data volume, which includes all database files. - -- **Script**: `backup-volume.ps1` -- **Output**: TAR archives in the `backups` directory, compressed as ZIP files -- **Retention**: Keeps the last 5 volume backups by default - -## Automated Backups - -You can set up automated daily backups using the included script: - -```powershell -.\schedule-backup.ps1 -``` - -This creates a Windows Scheduled Task that runs the database backup script daily at 3 AM. - -## Restoring from Backups - -### Restoring from a Database Dump - -```powershell -.\restore-gitea-db.ps1 -BackupFile "backups\gitea-db-backup-2025-03-01_10-30-00.sql.zip" -``` - -### Restoring from a Volume Backup - -```powershell -.\restore-volume.ps1 -BackupFile "backups\postgres-volume-backup-2025-03-01_10-30-00.tar.zip" -``` - -## Best Practices - -1. **Regular Backups**: Run backups at least daily -2. **Multiple Backup Methods**: Use both database dumps and volume backups -3. **Off-site Storage**: Copy your backups to an external drive or cloud storage -4. **Test Restores**: Periodically test restoring from your backups -5. **Version Control**: Keep your Gitea configuration files in version control - -## Important Notes - -- **Never** run `docker-compose down -v` unless you have a recent backup -- When upgrading Gitea, always create a backup first -- The database volume (`postgres-data`) persists even when containers are stopped or removed, but can be lost if explicitly deleted - -## Manual Backup Commands - -If you need to create a backup manually: - -```powershell -# Database dump -.\backup-gitea-db.ps1 - -# Volume backup -.\backup-volume.ps1 +# Gitea Backup Strategy + +This document outlines the backup strategy for your Gitea installation, focusing on ensuring your database is always backed up in at least one place. + +## Backup Methods + +This setup provides two complementary backup methods: + +### 1. PostgreSQL Database Dumps + +Database dumps are SQL files containing all your database data. These are the most reliable way to back up a PostgreSQL database. + +- **Script**: `backup-gitea-db.ps1` +- **Output**: SQL dumps in the `backups` directory, compressed as ZIP files +- **Retention**: Keeps the last 10 backups by default + +### 2. Docker Volume Backups + +This method backs up the entire PostgreSQL data volume, which includes all database files. + +- **Script**: `backup-volume.ps1` +- **Output**: TAR archives in the `backups` directory, compressed as ZIP files +- **Retention**: Keeps the last 5 volume backups by default + +## Automated Backups + +You can set up automated daily backups using the included script: + +```powershell +.\schedule-backup.ps1 +``` + +This creates a Windows Scheduled Task that runs the database backup script daily at 3 AM. + +## Restoring from Backups + +### Restoring from a Database Dump + +```powershell +.\restore-gitea-db.ps1 -BackupFile "backups\gitea-db-backup-2025-03-01_10-30-00.sql.zip" +``` + +### Restoring from a Volume Backup + +```powershell +.\restore-volume.ps1 -BackupFile "backups\postgres-volume-backup-2025-03-01_10-30-00.tar.zip" +``` + +## Best Practices + +1. **Regular Backups**: Run backups at least daily +2. **Multiple Backup Methods**: Use both database dumps and volume backups +3. **Off-site Storage**: Copy your backups to an external drive or cloud storage +4. **Test Restores**: Periodically test restoring from your backups +5. **Version Control**: Keep your Gitea configuration files in version control + +## Important Notes + +- **Never** run `docker-compose down -v` unless you have a recent backup +- When upgrading Gitea, always create a backup first +- The database volume (`postgres-data`) persists even when containers are stopped or removed, but can be lost if explicitly deleted + +## Manual Backup Commands + +If you need to create a backup manually: + +```powershell +# Database dump +.\backup-gitea-db.ps1 + +# Volume backup +.\backup-volume.ps1 ``` \ No newline at end of file diff --git a/HTTPS-SETUP.md b/HTTPS-SETUP.md index 926c4c6..0b0b0d7 100644 --- a/HTTPS-SETUP.md +++ b/HTTPS-SETUP.md @@ -1,81 +1,81 @@ -# Setting Up HTTPS for Gitea with Traefik - -This guide explains how to configure Gitea with proper HTTPS using Traefik as a reverse proxy with automatic certificate management via Let's Encrypt. - -## Prerequisites - -- A domain name pointing to your server (currently using `bee8333.ddns.net`) -- Ports 80 and 443 open and forwarded to your server -- Docker and Docker Compose installed - -## Configuration Steps - -1. **Update email address in docker-compose.yml** - - Edit the `docker-compose.yml` file and replace `your-email@example.com` with your actual email address. Let's Encrypt will use this for certificate expiration notifications: - - ```yaml - --certificatesresolvers.letsencrypt.acme.email=your-email@example.com - ``` - -2. **Start the services** - - ```bash - docker-compose down - docker-compose up -d - ``` - -3. **Check the status** - - ```bash - docker-compose ps - ``` - - All services should be running without errors. - -## How It Works - -- **Traefik** acts as a reverse proxy, handling incoming HTTP/HTTPS traffic -- Automatically redirects HTTP to HTTPS -- Obtains and renews SSL certificates from Let's Encrypt -- Routes requests to the appropriate containers based on domain name - -## Troubleshooting - -If you encounter issues: - -1. **Check Traefik logs** - - ```bash - docker-compose logs traefik - ``` - -2. **Check Gitea logs** - - ```bash - docker-compose logs server - ``` - -3. **Verify DNS settings** - - Make sure your domain (`bee8333.ddns.net`) correctly points to your server's IP address. - -4. **Check firewall settings** - - Ensure ports 80 and 443 are open and properly forwarded to your server. - -## Git Client Configuration - -When pushing to your Gitea repository from your local machine, you'll now be using HTTPS with a valid certificate. Use the following URL format: - -``` -https://bee8333.ddns.net/username/repository.git -``` - -## SSH Access - -SSH access is still available on port 222. Use the following format in your SSH config or Git command: - -``` -ssh://git@bee8333.ddns.net:222/username/repository.git +# Setting Up HTTPS for Gitea with Traefik + +This guide explains how to configure Gitea with proper HTTPS using Traefik as a reverse proxy with automatic certificate management via Let's Encrypt. + +## Prerequisites + +- A domain name pointing to your server (currently using `bee8333.ddns.net`) +- Ports 80 and 443 open and forwarded to your server +- Docker and Docker Compose installed + +## Configuration Steps + +1. **Update email address in docker-compose.yml** + + Edit the `docker-compose.yml` file and replace `your-email@example.com` with your actual email address. Let's Encrypt will use this for certificate expiration notifications: + + ```yaml + --certificatesresolvers.letsencrypt.acme.email=your-email@example.com + ``` + +2. **Start the services** + + ```bash + docker-compose down + docker-compose up -d + ``` + +3. **Check the status** + + ```bash + docker-compose ps + ``` + + All services should be running without errors. + +## How It Works + +- **Traefik** acts as a reverse proxy, handling incoming HTTP/HTTPS traffic +- Automatically redirects HTTP to HTTPS +- Obtains and renews SSL certificates from Let's Encrypt +- Routes requests to the appropriate containers based on domain name + +## Troubleshooting + +If you encounter issues: + +1. **Check Traefik logs** + + ```bash + docker-compose logs traefik + ``` + +2. **Check Gitea logs** + + ```bash + docker-compose logs server + ``` + +3. **Verify DNS settings** + + Make sure your domain (`bee8333.ddns.net`) correctly points to your server's IP address. + +4. **Check firewall settings** + + Ensure ports 80 and 443 are open and properly forwarded to your server. + +## Git Client Configuration + +When pushing to your Gitea repository from your local machine, you'll now be using HTTPS with a valid certificate. Use the following URL format: + +``` +https://bee8333.ddns.net/username/repository.git +``` + +## SSH Access + +SSH access is still available on port 222. Use the following format in your SSH config or Git command: + +``` +ssh://git@bee8333.ddns.net:222/username/repository.git ``` \ No newline at end of file diff --git a/README.md b/README.md index de6b63c..9ffed98 100644 --- a/README.md +++ b/README.md @@ -1,183 +1,183 @@ -# Gitea Docker Setup - -This is a Docker Compose configuration for running Gitea with PostgreSQL, configured with HTTPS support. - -## Prerequisites - -- Docker Desktop for Windows -- Docker Compose -- A domain or DDNS service (configured to point to your server) -- Port forwarding configured on your router (if accessing from outside your network) - -## Features - -- Gitea with HTTPS support -- PostgreSQL database -- SSH access for Git operations -- Persistent data storage -- Self-signed SSL certificates (can be replaced with Let's Encrypt) -- Automated database backup system - -## Configuration - -The setup includes: -- Gitea web interface: - - External access: https://bee8333.ddns.net/ - - Local network access: https://bee8333.ddns.net/ or https://localhost:3000 - - Local development: https://127.0.0.1:3000 -- SSH access on port 222 (for git clone/push/pull) -- PostgreSQL database (internal access only) -- SSL certificates in `./gitea/ssl/` -- Persistent data storage for both Gitea and PostgreSQL - -## Access Methods - -### Web Interface - -1. **External Access (Internet)**: - - URL: https://bee8333.ddns.net/ - - Requires port 3000 forwarded on your router - - Uses HTTPS with SSL certificate - -2. **Local Network Access**: - - Same URL: https://bee8333.ddns.net/ - - Or use: https://localhost:3000 - - Both use HTTPS with SSL certificate - - No port forwarding needed - -3. **Local Development**: - - URL: https://127.0.0.1:3000 - - Direct access on the hosting machine - - Uses HTTPS with SSL certificate - -### Git Operations (SSH) - -- External SSH URL: `ssh://git@bee8333.ddns.net:222/username/repository.git` -- Local SSH URL: `ssh://git@localhost:222/username/repository.git` -- Requires port 222 forwarded on your router for external access - -## Getting Started - -1. Make sure Docker Desktop is running -2. Clone this repository -3. Open a terminal in this directory -4. Generate SSL certificates (see [SSL Certificates](#ssl-certificates) section) -5. Run `docker-compose up -d` -6. Access Gitea using one of the URLs above -7. During first-time setup: - - Database settings are pre-configured (no changes needed) - - Domain is set to your domain name - - SSH port is set to 222 - - HTTPS is enabled by default - -## SSL Certificates - -You'll need to generate SSL certificates before starting the service. The certificates should be placed in `./gitea/ssl/`: -- `cert.pem` - The SSL certificate -- `key.pem` - The private key - -To generate self-signed certificates (for development/testing): - -```bash -# Create the ssl directory -mkdir -p gitea/ssl - -# Generate certificates using OpenSSL -docker run --rm -v ${PWD}/gitea/ssl:/ssl alpine/openssl req -x509 -nodes \ - -days 365 -newkey rsa:2048 \ - -keyout /ssl/key.pem -out /ssl/cert.pem \ - -subj "/CN=your.domain.here" -``` - -Replace `your.domain.here` with your actual domain name. - -**Security Notes:** -- Never commit SSL certificates to version control -- Keep your private key (key.pem) secure -- For production use, consider using Let's Encrypt certificates -- Self-signed certificates will show browser security warnings - -## Backup System - -This setup includes a comprehensive backup strategy to ensure your Gitea data is always protected. The backup system provides two complementary methods: - -### Database Backups - -PowerShell scripts are included to manage database backups: - -1. **Creating Backups**: - ```powershell - powershell -ExecutionPolicy Bypass -File .\backup-gitea-db.ps1 - ``` - This creates a SQL dump of your PostgreSQL database, compressed as a ZIP file in the `backups` directory. - -2. **Volume Backups**: - ```powershell - powershell -ExecutionPolicy Bypass -File .\backup-volume.ps1 - ``` - This backs up the entire PostgreSQL data volume as a TAR archive, compressed as a ZIP file. - -3. **Automated Backups**: - ```powershell - powershell -ExecutionPolicy Bypass -File .\schedule-backup.ps1 - ``` - This creates a Windows Scheduled Task that runs database backups daily at 3 AM. - -4. **Restoring from Backups**: - ```powershell - # Restore from database dump - powershell -ExecutionPolicy Bypass -File .\restore-gitea-db.ps1 -BackupFile "backups\your-backup-file.sql.zip" - - # Restore from volume backup - powershell -ExecutionPolicy Bypass -File .\restore-volume.ps1 -BackupFile "backups\your-volume-backup.tar.zip" - ``` - -### Backup Best Practices - -- Keep multiple backups using both methods (database dumps and volume backups) -- Store backups in multiple locations (local and off-site) -- Test restoring from backups periodically -- Create a backup before upgrading Gitea or making significant changes -- **Never** run `docker-compose down -v` unless you have a recent backup - -For more detailed information about the backup system, see [BACKUP-README.md](BACKUP-README.md). - -## Stopping the Services - -To stop the services, run: -```bash -docker-compose down -``` - -**Important**: Do not use the `-v` flag (`docker-compose down -v`) unless you intend to delete all data, as this will remove the Docker volumes containing your database. - -## Data Persistence - -All data is stored in Docker volumes and local directories: -- `./gitea/` - Gitea configuration and data - - `./gitea/ssl/` - SSL certificates - - `./gitea/conf/` - Gitea configuration -- Docker volumes (managed by Docker): - - `gitea-data` - Gitea repositories and application data - - `postgres-data` - PostgreSQL database files -- `./backups/` - Database and volume backups - -## Troubleshooting - -1. **Cannot access externally**: - - Verify port 3000 (HTTP) and 222 (SSH) are forwarded on your router - - Check your DDNS service is updating correctly - - Ensure your domain points to your correct IP - -2. **SSL Certificate Warnings**: - - This is normal with self-signed certificates - - For production, consider using Let's Encrypt certificates - -3. **Local Network Access**: - - If bee8333.ddns.net doesn't resolve locally, use localhost:3000 instead - - Add an entry to your hosts file if needed - -4. **Database Backup Issues**: - - Ensure Docker is running when attempting backups - - Check that the container names match those in the backup scripts +# Gitea Docker Setup + +This is a Docker Compose configuration for running Gitea with PostgreSQL, configured with HTTPS support. + +## Prerequisites + +- Docker Desktop for Windows +- Docker Compose +- A domain or DDNS service (configured to point to your server) +- Port forwarding configured on your router (if accessing from outside your network) + +## Features + +- Gitea with HTTPS support +- PostgreSQL database +- SSH access for Git operations +- Persistent data storage +- Self-signed SSL certificates (can be replaced with Let's Encrypt) +- Automated database backup system + +## Configuration + +The setup includes: +- Gitea web interface: + - External access: https://bee8333.ddns.net/ + - Local network access: https://bee8333.ddns.net/ or https://localhost:3000 + - Local development: https://127.0.0.1:3000 +- SSH access on port 222 (for git clone/push/pull) +- PostgreSQL database (internal access only) +- SSL certificates in `./gitea/ssl/` +- Persistent data storage for both Gitea and PostgreSQL + +## Access Methods + +### Web Interface + +1. **External Access (Internet)**: + - URL: https://bee8333.ddns.net/ + - Requires port 3000 forwarded on your router + - Uses HTTPS with SSL certificate + +2. **Local Network Access**: + - Same URL: https://bee8333.ddns.net/ + - Or use: https://localhost:3000 + - Both use HTTPS with SSL certificate + - No port forwarding needed + +3. **Local Development**: + - URL: https://127.0.0.1:3000 + - Direct access on the hosting machine + - Uses HTTPS with SSL certificate + +### Git Operations (SSH) + +- External SSH URL: `ssh://git@bee8333.ddns.net:222/username/repository.git` +- Local SSH URL: `ssh://git@localhost:222/username/repository.git` +- Requires port 222 forwarded on your router for external access + +## Getting Started + +1. Make sure Docker Desktop is running +2. Clone this repository +3. Open a terminal in this directory +4. Generate SSL certificates (see [SSL Certificates](#ssl-certificates) section) +5. Run `docker-compose up -d` +6. Access Gitea using one of the URLs above +7. During first-time setup: + - Database settings are pre-configured (no changes needed) + - Domain is set to your domain name + - SSH port is set to 222 + - HTTPS is enabled by default + +## SSL Certificates + +You'll need to generate SSL certificates before starting the service. The certificates should be placed in `./gitea/ssl/`: +- `cert.pem` - The SSL certificate +- `key.pem` - The private key + +To generate self-signed certificates (for development/testing): + +```bash +# Create the ssl directory +mkdir -p gitea/ssl + +# Generate certificates using OpenSSL +docker run --rm -v ${PWD}/gitea/ssl:/ssl alpine/openssl req -x509 -nodes \ + -days 365 -newkey rsa:2048 \ + -keyout /ssl/key.pem -out /ssl/cert.pem \ + -subj "/CN=your.domain.here" +``` + +Replace `your.domain.here` with your actual domain name. + +**Security Notes:** +- Never commit SSL certificates to version control +- Keep your private key (key.pem) secure +- For production use, consider using Let's Encrypt certificates +- Self-signed certificates will show browser security warnings + +## Backup System + +This setup includes a comprehensive backup strategy to ensure your Gitea data is always protected. The backup system provides two complementary methods: + +### Database Backups + +PowerShell scripts are included to manage database backups: + +1. **Creating Backups**: + ```powershell + powershell -ExecutionPolicy Bypass -File .\backup-gitea-db.ps1 + ``` + This creates a SQL dump of your PostgreSQL database, compressed as a ZIP file in the `backups` directory. + +2. **Volume Backups**: + ```powershell + powershell -ExecutionPolicy Bypass -File .\backup-volume.ps1 + ``` + This backs up the entire PostgreSQL data volume as a TAR archive, compressed as a ZIP file. + +3. **Automated Backups**: + ```powershell + powershell -ExecutionPolicy Bypass -File .\schedule-backup.ps1 + ``` + This creates a Windows Scheduled Task that runs database backups daily at 3 AM. + +4. **Restoring from Backups**: + ```powershell + # Restore from database dump + powershell -ExecutionPolicy Bypass -File .\restore-gitea-db.ps1 -BackupFile "backups\your-backup-file.sql.zip" + + # Restore from volume backup + powershell -ExecutionPolicy Bypass -File .\restore-volume.ps1 -BackupFile "backups\your-volume-backup.tar.zip" + ``` + +### Backup Best Practices + +- Keep multiple backups using both methods (database dumps and volume backups) +- Store backups in multiple locations (local and off-site) +- Test restoring from backups periodically +- Create a backup before upgrading Gitea or making significant changes +- **Never** run `docker-compose down -v` unless you have a recent backup + +For more detailed information about the backup system, see [BACKUP-README.md](BACKUP-README.md). + +## Stopping the Services + +To stop the services, run: +```bash +docker-compose down +``` + +**Important**: Do not use the `-v` flag (`docker-compose down -v`) unless you intend to delete all data, as this will remove the Docker volumes containing your database. + +## Data Persistence + +All data is stored in Docker volumes and local directories: +- `./gitea/` - Gitea configuration and data + - `./gitea/ssl/` - SSL certificates + - `./gitea/conf/` - Gitea configuration +- Docker volumes (managed by Docker): + - `gitea-data` - Gitea repositories and application data + - `postgres-data` - PostgreSQL database files +- `./backups/` - Database and volume backups + +## Troubleshooting + +1. **Cannot access externally**: + - Verify port 3000 (HTTP) and 222 (SSH) are forwarded on your router + - Check your DDNS service is updating correctly + - Ensure your domain points to your correct IP + +2. **SSL Certificate Warnings**: + - This is normal with self-signed certificates + - For production, consider using Let's Encrypt certificates + +3. **Local Network Access**: + - If bee8333.ddns.net doesn't resolve locally, use localhost:3000 instead + - Add an entry to your hosts file if needed + +4. **Database Backup Issues**: + - Ensure Docker is running when attempting backups + - Check that the container names match those in the backup scripts - For PowerShell execution issues, use the `-ExecutionPolicy Bypass` flag \ No newline at end of file diff --git a/backup-gitea-db.ps1 b/backup-gitea-db.ps1 index b2c4db1..6e1af9e 100644 --- a/backup-gitea-db.ps1 +++ b/backup-gitea-db.ps1 @@ -1,82 +1,82 @@ -# Gitea Database Backup Script -$timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss" -$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path -$backupDir = Join-Path $scriptDir "backups" -$backupFile = Join-Path $backupDir "gitea-db-backup-$timestamp.sql" -$redundantBackupDir = "D:\Pr00jects\gitea-docker" - -# Ensure backup directory exists -if (-not (Test-Path $backupDir)) { - New-Item -ItemType Directory -Path $backupDir -} - -# Ensure redundant backup directory exists -if (-not (Test-Path $redundantBackupDir)) { - try { - New-Item -ItemType Directory -Path $redundantBackupDir -Force - } catch { - "[$timestamp] Warning: Could not create redundant backup directory at $redundantBackupDir. Error: $_" | Out-File -Append -FilePath $logFile - } -} - -# Log execution of the script -$logFile = Join-Path $backupDir "backup-log.txt" -"[$timestamp] Starting database backup..." | Out-File -Append -FilePath $logFile - -# Check if Docker is running -$dockerRunning = $false -try { - $dockerStatus = docker info 2>&1 - $dockerRunning = $LASTEXITCODE -eq 0 -} catch { - $dockerRunning = $false -} - -if (-not $dockerRunning) { - "[$timestamp] Error: Docker is not running. Backup failed." | Out-File -Append -FilePath $logFile - exit 1 -} - -# Check if Gitea container is running -$containerRunning = docker ps --format "{{.Names}}" | Select-String -Pattern "gitea-db" -Quiet -if (-not $containerRunning) { - "[$timestamp] Error: Gitea database container is not running. Backup failed." | Out-File -Append -FilePath $logFile - exit 1 -} - -# Create database dump -"[$timestamp] Creating database backup to $backupFile..." | Out-File -Append -FilePath $logFile -docker exec gitea-db pg_dump -U gitea -d gitea > $backupFile - -# Check if backup was successful -if ($LASTEXITCODE -eq 0 -and (Test-Path $backupFile) -and (Get-Item $backupFile).Length -gt 0) { - "[$timestamp] Backup completed successfully!" | Out-File -Append -FilePath $logFile - - # Optional: Compress the backup file - $zipFileName = "$backupFile.zip" - Compress-Archive -Path $backupFile -DestinationPath $zipFileName -Force - Remove-Item $backupFile - "[$timestamp] Backup compressed to $zipFileName" | Out-File -Append -FilePath $logFile - - # Copy backup to redundant location - if (Test-Path $redundantBackupDir) { - try { - $redundantBackupFile = Join-Path $redundantBackupDir (Split-Path -Leaf $zipFileName) - Copy-Item -Path $zipFileName -Destination $redundantBackupFile -Force - "[$timestamp] Backup copied to redundant location: $redundantBackupFile" | Out-File -Append -FilePath $logFile - } catch { - "[$timestamp] Error copying backup to redundant location: $_" | Out-File -Append -FilePath $logFile - } - } else { - "[$timestamp] Warning: Redundant backup directory not found: $redundantBackupDir" | Out-File -Append -FilePath $logFile - } -} else { - "[$timestamp] Backup failed!" | Out-File -Append -FilePath $logFile -} - -# Optional: Clean up old backups (keep last 10) -$oldBackups = Get-ChildItem -Path $backupDir -Filter "gitea-db-backup-*.zip" | Sort-Object LastWriteTime -Descending | Select-Object -Skip 10 -foreach ($backup in $oldBackups) { - Remove-Item $backup.FullName - "[$timestamp] Removed old backup: $($backup.Name)" | Out-File -Append -FilePath $logFile +# Gitea Database Backup Script +$timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss" +$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path +$backupDir = Join-Path $scriptDir "backups" +$backupFile = Join-Path $backupDir "gitea-db-backup-$timestamp.sql" +$redundantBackupDir = "D:\Pr00jects\gitea-docker" + +# Ensure backup directory exists +if (-not (Test-Path $backupDir)) { + New-Item -ItemType Directory -Path $backupDir +} + +# Ensure redundant backup directory exists +if (-not (Test-Path $redundantBackupDir)) { + try { + New-Item -ItemType Directory -Path $redundantBackupDir -Force + } catch { + "[$timestamp] Warning: Could not create redundant backup directory at $redundantBackupDir. Error: $_" | Out-File -Append -FilePath $logFile + } +} + +# Log execution of the script +$logFile = Join-Path $backupDir "backup-log.txt" +"[$timestamp] Starting database backup..." | Out-File -Append -FilePath $logFile + +# Check if Docker is running +$dockerRunning = $false +try { + $dockerStatus = docker info 2>&1 + $dockerRunning = $LASTEXITCODE -eq 0 +} catch { + $dockerRunning = $false +} + +if (-not $dockerRunning) { + "[$timestamp] Error: Docker is not running. Backup failed." | Out-File -Append -FilePath $logFile + exit 1 +} + +# Check if Gitea container is running +$containerRunning = docker ps --format "{{.Names}}" | Select-String -Pattern "gitea-db" -Quiet +if (-not $containerRunning) { + "[$timestamp] Error: Gitea database container is not running. Backup failed." | Out-File -Append -FilePath $logFile + exit 1 +} + +# Create database dump +"[$timestamp] Creating database backup to $backupFile..." | Out-File -Append -FilePath $logFile +docker exec gitea-db pg_dump -U gitea -d gitea > $backupFile + +# Check if backup was successful +if ($LASTEXITCODE -eq 0 -and (Test-Path $backupFile) -and (Get-Item $backupFile).Length -gt 0) { + "[$timestamp] Backup completed successfully!" | Out-File -Append -FilePath $logFile + + # Optional: Compress the backup file + $zipFileName = "$backupFile.zip" + Compress-Archive -Path $backupFile -DestinationPath $zipFileName -Force + Remove-Item $backupFile + "[$timestamp] Backup compressed to $zipFileName" | Out-File -Append -FilePath $logFile + + # Copy backup to redundant location + if (Test-Path $redundantBackupDir) { + try { + $redundantBackupFile = Join-Path $redundantBackupDir (Split-Path -Leaf $zipFileName) + Copy-Item -Path $zipFileName -Destination $redundantBackupFile -Force + "[$timestamp] Backup copied to redundant location: $redundantBackupFile" | Out-File -Append -FilePath $logFile + } catch { + "[$timestamp] Error copying backup to redundant location: $_" | Out-File -Append -FilePath $logFile + } + } else { + "[$timestamp] Warning: Redundant backup directory not found: $redundantBackupDir" | Out-File -Append -FilePath $logFile + } +} else { + "[$timestamp] Backup failed!" | Out-File -Append -FilePath $logFile +} + +# Optional: Clean up old backups (keep last 10) +$oldBackups = Get-ChildItem -Path $backupDir -Filter "gitea-db-backup-*.zip" | Sort-Object LastWriteTime -Descending | Select-Object -Skip 10 +foreach ($backup in $oldBackups) { + Remove-Item $backup.FullName + "[$timestamp] Removed old backup: $($backup.Name)" | Out-File -Append -FilePath $logFile } \ No newline at end of file diff --git a/backup-volume.ps1 b/backup-volume.ps1 index ff346f9..1272ba5 100644 --- a/backup-volume.ps1 +++ b/backup-volume.ps1 @@ -1,88 +1,88 @@ -# Script to backup the entire Postgres Docker volume -$timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss" -$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path -$backupDir = Join-Path $scriptDir "backups" -$volumeName = "gitea-docker_postgres-data" -$backupFile = "postgres-volume-backup-$timestamp.tar" -$backupFilePath = Join-Path $backupDir $backupFile -$redundantBackupDir = "D:\Pr00jects\gitea-docker" -$logFile = Join-Path $backupDir "volume-backup-log.txt" -$currentDir = Get-Location - -# Ensure backup directory exists -if (-not (Test-Path $backupDir)) { - New-Item -ItemType Directory -Path $backupDir -} - -# Ensure redundant backup directory exists -if (-not (Test-Path $redundantBackupDir)) { - try { - New-Item -ItemType Directory -Path $redundantBackupDir -Force - } catch { - Add-Content -Path $logFile -Value "[$timestamp] Warning: Could not create redundant backup directory at $redundantBackupDir. Error: $_" - } -} - -# Log start of backup -Add-Content -Path $logFile -Value "[$timestamp] Starting volume backup for $volumeName..." - -# Check if volume exists -$volumeExists = docker volume ls --format "{{.Name}}" | Select-String -Pattern "^$volumeName$" -if (-not $volumeExists) { - Write-Host "Volume $volumeName not found!" -ForegroundColor Red - Add-Content -Path $logFile -Value "[$timestamp] Error: Volume $volumeName not found!" - exit 1 -} - -# Create a temporary container to access the volume -Write-Host "Creating backup of Docker volume $volumeName..." -Add-Content -Path $logFile -Value "[$timestamp] Creating backup to $backupFilePath..." - -# Change to backup directory and use simple relative paths for Docker -Set-Location -Path $backupDir -docker run --rm -v ${volumeName}:/volume -v ${PWD}:/backup alpine tar -cf /backup/$backupFile -C /volume ./ - -# Restore original directory -Set-Location -Path $currentDir - -# Check if backup was successful -if ($LASTEXITCODE -eq 0 -and (Test-Path $backupFilePath) -and (Get-Item $backupFilePath).Length -gt 0) { - Write-Host "Volume backup completed successfully to $backupFilePath!" -ForegroundColor Green - Add-Content -Path $logFile -Value "[$timestamp] Volume backup completed successfully!" - - # Optional: Compress the backup file - Write-Host "Compressing backup file..." - Add-Content -Path $logFile -Value "[$timestamp] Compressing backup file..." - $zipFileName = "$backupFilePath.zip" - Compress-Archive -Path $backupFilePath -DestinationPath $zipFileName -Force - Remove-Item $backupFilePath - Write-Host "Backup compressed to $zipFileName" -ForegroundColor Green - Add-Content -Path $logFile -Value "[$timestamp] Backup compressed to $zipFileName" - - # Copy backup to redundant location - if (Test-Path $redundantBackupDir) { - try { - $redundantBackupFile = Join-Path $redundantBackupDir (Split-Path -Leaf $zipFileName) - Copy-Item -Path $zipFileName -Destination $redundantBackupFile -Force - Write-Host "Backup copied to redundant location: $redundantBackupFile" -ForegroundColor Green - Add-Content -Path $logFile -Value "[$timestamp] Backup copied to redundant location: $redundantBackupFile" - } catch { - Write-Host "Error copying backup to redundant location: $_" -ForegroundColor Red - Add-Content -Path $logFile -Value "[$timestamp] Error copying backup to redundant location: $_" - } - } else { - Write-Host "Warning: Redundant backup directory not found: $redundantBackupDir" -ForegroundColor Yellow - Add-Content -Path $logFile -Value "[$timestamp] Warning: Redundant backup directory not found: $redundantBackupDir" - } -} else { - Write-Host "Volume backup failed!" -ForegroundColor Red - Add-Content -Path $logFile -Value "[$timestamp] Volume backup failed!" -} - -# Optional: Clean up old volume backups (keep last 5) -$oldBackups = Get-ChildItem -Path $backupDir -Filter "postgres-volume-backup-*.zip" | Sort-Object LastWriteTime -Descending | Select-Object -Skip 5 -foreach ($backup in $oldBackups) { - Remove-Item $backup.FullName - Write-Host "Removed old volume backup: $($backup.Name)" - Add-Content -Path $logFile -Value "[$timestamp] Removed old volume backup: $($backup.Name)" +# Script to backup the entire Postgres Docker volume +$timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss" +$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path +$backupDir = Join-Path $scriptDir "backups" +$volumeName = "gitea-docker_postgres-data" +$backupFile = "postgres-volume-backup-$timestamp.tar" +$backupFilePath = Join-Path $backupDir $backupFile +$redundantBackupDir = "D:\Pr00jects\gitea-docker" +$logFile = Join-Path $backupDir "volume-backup-log.txt" +$currentDir = Get-Location + +# Ensure backup directory exists +if (-not (Test-Path $backupDir)) { + New-Item -ItemType Directory -Path $backupDir +} + +# Ensure redundant backup directory exists +if (-not (Test-Path $redundantBackupDir)) { + try { + New-Item -ItemType Directory -Path $redundantBackupDir -Force + } catch { + Add-Content -Path $logFile -Value "[$timestamp] Warning: Could not create redundant backup directory at $redundantBackupDir. Error: $_" + } +} + +# Log start of backup +Add-Content -Path $logFile -Value "[$timestamp] Starting volume backup for $volumeName..." + +# Check if volume exists +$volumeExists = docker volume ls --format "{{.Name}}" | Select-String -Pattern "^$volumeName$" +if (-not $volumeExists) { + Write-Host "Volume $volumeName not found!" -ForegroundColor Red + Add-Content -Path $logFile -Value "[$timestamp] Error: Volume $volumeName not found!" + exit 1 +} + +# Create a temporary container to access the volume +Write-Host "Creating backup of Docker volume $volumeName..." +Add-Content -Path $logFile -Value "[$timestamp] Creating backup to $backupFilePath..." + +# Change to backup directory and use simple relative paths for Docker +Set-Location -Path $backupDir +docker run --rm -v ${volumeName}:/volume -v ${PWD}:/backup alpine tar -cf /backup/$backupFile -C /volume ./ + +# Restore original directory +Set-Location -Path $currentDir + +# Check if backup was successful +if ($LASTEXITCODE -eq 0 -and (Test-Path $backupFilePath) -and (Get-Item $backupFilePath).Length -gt 0) { + Write-Host "Volume backup completed successfully to $backupFilePath!" -ForegroundColor Green + Add-Content -Path $logFile -Value "[$timestamp] Volume backup completed successfully!" + + # Optional: Compress the backup file + Write-Host "Compressing backup file..." + Add-Content -Path $logFile -Value "[$timestamp] Compressing backup file..." + $zipFileName = "$backupFilePath.zip" + Compress-Archive -Path $backupFilePath -DestinationPath $zipFileName -Force + Remove-Item $backupFilePath + Write-Host "Backup compressed to $zipFileName" -ForegroundColor Green + Add-Content -Path $logFile -Value "[$timestamp] Backup compressed to $zipFileName" + + # Copy backup to redundant location + if (Test-Path $redundantBackupDir) { + try { + $redundantBackupFile = Join-Path $redundantBackupDir (Split-Path -Leaf $zipFileName) + Copy-Item -Path $zipFileName -Destination $redundantBackupFile -Force + Write-Host "Backup copied to redundant location: $redundantBackupFile" -ForegroundColor Green + Add-Content -Path $logFile -Value "[$timestamp] Backup copied to redundant location: $redundantBackupFile" + } catch { + Write-Host "Error copying backup to redundant location: $_" -ForegroundColor Red + Add-Content -Path $logFile -Value "[$timestamp] Error copying backup to redundant location: $_" + } + } else { + Write-Host "Warning: Redundant backup directory not found: $redundantBackupDir" -ForegroundColor Yellow + Add-Content -Path $logFile -Value "[$timestamp] Warning: Redundant backup directory not found: $redundantBackupDir" + } +} else { + Write-Host "Volume backup failed!" -ForegroundColor Red + Add-Content -Path $logFile -Value "[$timestamp] Volume backup failed!" +} + +# Optional: Clean up old volume backups (keep last 5) +$oldBackups = Get-ChildItem -Path $backupDir -Filter "postgres-volume-backup-*.zip" | Sort-Object LastWriteTime -Descending | Select-Object -Skip 5 +foreach ($backup in $oldBackups) { + Remove-Item $backup.FullName + Write-Host "Removed old volume backup: $($backup.Name)" + Add-Content -Path $logFile -Value "[$timestamp] Removed old volume backup: $($backup.Name)" } \ No newline at end of file diff --git a/backups/backup-log.txt b/backups/backup-log.txt index 21f5373..91dc5f0 100644 Binary files a/backups/backup-log.txt and b/backups/backup-log.txt differ diff --git a/backups/gitea-db-backup-2025-03-08_23-02-54.sql.zip b/backups/gitea-db-backup-2025-03-08_23-02-54.sql.zip deleted file mode 100644 index 1e937cf..0000000 Binary files a/backups/gitea-db-backup-2025-03-08_23-02-54.sql.zip and /dev/null differ diff --git a/backups/gitea-db-backup-2025-03-08_23-09-03.sql.zip b/backups/gitea-db-backup-2025-03-08_23-09-03.sql.zip deleted file mode 100644 index 5535c7a..0000000 Binary files a/backups/gitea-db-backup-2025-03-08_23-09-03.sql.zip and /dev/null differ diff --git a/backups/gitea-db-backup-2025-03-28_18-23-22.sql.zip b/backups/gitea-db-backup-2025-03-28_18-23-22.sql.zip deleted file mode 100644 index 8abcfc0..0000000 Binary files a/backups/gitea-db-backup-2025-03-28_18-23-22.sql.zip and /dev/null differ diff --git a/backups/gitea-db-backup-2025-04-19_19-32-22.sql.zip b/backups/gitea-db-backup-2025-04-19_19-32-22.sql.zip deleted file mode 100644 index a18ba2a..0000000 Binary files a/backups/gitea-db-backup-2025-04-19_19-32-22.sql.zip and /dev/null differ diff --git a/backups/gitea-db-backup-2025-04-19_19-34-24.sql.zip b/backups/gitea-db-backup-2025-04-19_19-34-24.sql.zip deleted file mode 100644 index 140ef4f..0000000 Binary files a/backups/gitea-db-backup-2025-04-19_19-34-24.sql.zip and /dev/null differ diff --git a/backups/gitea-db-backup-2025-04-19_19-35-59.sql.zip b/backups/gitea-db-backup-2025-04-19_19-35-59.sql.zip deleted file mode 100644 index 024aea8..0000000 Binary files a/backups/gitea-db-backup-2025-04-19_19-35-59.sql.zip and /dev/null differ diff --git a/backups/gitea-db-backup-2025-04-19_19-40-45.sql.zip b/backups/gitea-db-backup-2025-04-19_19-40-45.sql.zip deleted file mode 100644 index d24ff69..0000000 Binary files a/backups/gitea-db-backup-2025-04-19_19-40-45.sql.zip and /dev/null differ diff --git a/backups/gitea-db-backup-2025-04-19_19-41-01.sql.zip b/backups/gitea-db-backup-2025-04-19_19-41-01.sql.zip deleted file mode 100644 index df77ba9..0000000 Binary files a/backups/gitea-db-backup-2025-04-19_19-41-01.sql.zip and /dev/null differ diff --git a/backups/gitea-db-backup-2025-04-19_19-43-44.sql.zip b/backups/gitea-db-backup-2025-04-19_19-43-44.sql.zip deleted file mode 100644 index fc66f55..0000000 Binary files a/backups/gitea-db-backup-2025-04-19_19-43-44.sql.zip and /dev/null differ diff --git a/backups/gitea-db-backup-2025-04-19_19-44-36.sql.zip b/backups/gitea-db-backup-2025-04-19_19-44-36.sql.zip deleted file mode 100644 index ac5020d..0000000 Binary files a/backups/gitea-db-backup-2025-04-19_19-44-36.sql.zip and /dev/null differ diff --git a/backups/gitea-db-backup-2025-04-21_03-03-47.sql.zip b/backups/gitea-db-backup-2025-04-21_03-03-47.sql.zip new file mode 100644 index 0000000..8658f6b Binary files /dev/null and b/backups/gitea-db-backup-2025-04-21_03-03-47.sql.zip differ diff --git a/backups/gitea-db-backup-2025-04-22_03-07-16.sql.zip b/backups/gitea-db-backup-2025-04-22_03-07-16.sql.zip new file mode 100644 index 0000000..814da3a Binary files /dev/null and b/backups/gitea-db-backup-2025-04-22_03-07-16.sql.zip differ diff --git a/backups/gitea-db-backup-2025-04-23_03-00-49.sql.zip b/backups/gitea-db-backup-2025-04-23_03-00-49.sql.zip new file mode 100644 index 0000000..8f4ce24 Binary files /dev/null and b/backups/gitea-db-backup-2025-04-23_03-00-49.sql.zip differ diff --git a/backups/gitea-db-backup-2025-04-25_19-01-37.sql b/backups/gitea-db-backup-2025-04-25_19-01-37.sql new file mode 100644 index 0000000..39185d1 Binary files /dev/null and b/backups/gitea-db-backup-2025-04-25_19-01-37.sql differ diff --git a/backups/gitea-db-backup-2025-05-18_01-16-38.sql.zip b/backups/gitea-db-backup-2025-05-18_01-16-38.sql.zip new file mode 100644 index 0000000..6706cec Binary files /dev/null and b/backups/gitea-db-backup-2025-05-18_01-16-38.sql.zip differ diff --git a/backups/gitea-db-backup-2025-05-18_03-00-05.sql.zip b/backups/gitea-db-backup-2025-05-18_03-00-05.sql.zip new file mode 100644 index 0000000..9f36ab7 Binary files /dev/null and b/backups/gitea-db-backup-2025-05-18_03-00-05.sql.zip differ diff --git a/backups/gitea-db-backup-2025-05-19_03-00-05.sql.zip b/backups/gitea-db-backup-2025-05-19_03-00-05.sql.zip new file mode 100644 index 0000000..5c7735e Binary files /dev/null and b/backups/gitea-db-backup-2025-05-19_03-00-05.sql.zip differ diff --git a/backups/gitea-db-backup-2025-05-20_03-00-53.sql.zip b/backups/gitea-db-backup-2025-05-20_03-00-53.sql.zip new file mode 100644 index 0000000..7d6ad45 Binary files /dev/null and b/backups/gitea-db-backup-2025-05-20_03-00-53.sql.zip differ diff --git a/backups/gitea-db-backup-2025-05-21_03-03-22.sql.zip b/backups/gitea-db-backup-2025-05-21_03-03-22.sql.zip new file mode 100644 index 0000000..0237e1d Binary files /dev/null and b/backups/gitea-db-backup-2025-05-21_03-03-22.sql.zip differ diff --git a/backups/gitea-db-backup-2025-05-22_03-03-36.sql.zip b/backups/gitea-db-backup-2025-05-22_03-03-36.sql.zip new file mode 100644 index 0000000..969b91c Binary files /dev/null and b/backups/gitea-db-backup-2025-05-22_03-03-36.sql.zip differ diff --git a/backups/gitea-db-backup-2025-05-23_03-21-26.sql b/backups/gitea-db-backup-2025-05-23_03-21-26.sql new file mode 100644 index 0000000..06656ea Binary files /dev/null and b/backups/gitea-db-backup-2025-05-23_03-21-26.sql differ diff --git a/backups/gitea-db-backup-2025-05-28_02-42-28.sql b/backups/gitea-db-backup-2025-05-28_02-42-28.sql new file mode 100644 index 0000000..3fd52fd Binary files /dev/null and b/backups/gitea-db-backup-2025-05-28_02-42-28.sql differ diff --git a/backups/gitea-db-backup-2025-06-09_21-22-55.sql.zip b/backups/gitea-db-backup-2025-06-09_21-22-55.sql.zip new file mode 100644 index 0000000..809cd7d Binary files /dev/null and b/backups/gitea-db-backup-2025-06-09_21-22-55.sql.zip differ diff --git a/backups/postgres-volume-backup-2025-03-01_23-23-13.tar.zip b/backups/postgres-volume-backup-2025-03-01_23-23-13.tar.zip deleted file mode 100644 index 7a1f6a1..0000000 Binary files a/backups/postgres-volume-backup-2025-03-01_23-23-13.tar.zip and /dev/null differ diff --git a/backups/postgres-volume-backup-2025-04-19_19-42-55.tar.zip b/backups/postgres-volume-backup-2025-05-19_03-00-14.tar.zip similarity index 52% rename from backups/postgres-volume-backup-2025-04-19_19-42-55.tar.zip rename to backups/postgres-volume-backup-2025-05-19_03-00-14.tar.zip index 23266b6..a01ef41 100644 Binary files a/backups/postgres-volume-backup-2025-04-19_19-42-55.tar.zip and b/backups/postgres-volume-backup-2025-05-19_03-00-14.tar.zip differ diff --git a/backups/postgres-volume-backup-2025-04-19_19-43-53.tar.zip b/backups/postgres-volume-backup-2025-05-20_03-14-23.tar.zip similarity index 52% rename from backups/postgres-volume-backup-2025-04-19_19-43-53.tar.zip rename to backups/postgres-volume-backup-2025-05-20_03-14-23.tar.zip index 33cd340..9b62e62 100644 Binary files a/backups/postgres-volume-backup-2025-04-19_19-43-53.tar.zip and b/backups/postgres-volume-backup-2025-05-20_03-14-23.tar.zip differ diff --git a/backups/postgres-volume-backup-2025-04-19_19-44-40.tar.zip b/backups/postgres-volume-backup-2025-05-21_03-08-24.tar.zip similarity index 51% rename from backups/postgres-volume-backup-2025-04-19_19-44-40.tar.zip rename to backups/postgres-volume-backup-2025-05-21_03-08-24.tar.zip index f7d7500..f3ae6ca 100644 Binary files a/backups/postgres-volume-backup-2025-04-19_19-44-40.tar.zip and b/backups/postgres-volume-backup-2025-05-21_03-08-24.tar.zip differ diff --git a/backups/postgres-volume-backup-2025-05-22_03-03-49.tar.zip b/backups/postgres-volume-backup-2025-05-22_03-03-49.tar.zip new file mode 100644 index 0000000..d68c856 Binary files /dev/null and b/backups/postgres-volume-backup-2025-05-22_03-03-49.tar.zip differ diff --git a/backups/postgres-volume-backup-2025-05-23_08-01-05.tar b/backups/postgres-volume-backup-2025-05-23_08-01-05.tar new file mode 100644 index 0000000..0abe80b Binary files /dev/null and b/backups/postgres-volume-backup-2025-05-23_08-01-05.tar differ diff --git a/backups/postgres-volume-backup-2025-06-09_21-30-15.tar.zip b/backups/postgres-volume-backup-2025-06-09_21-30-15.tar.zip new file mode 100644 index 0000000..060a273 Binary files /dev/null and b/backups/postgres-volume-backup-2025-06-09_21-30-15.tar.zip differ diff --git a/backups/postgres-volume-backup.tar b/backups/postgres-volume-backup.tar new file mode 100644 index 0000000..c5f22e5 Binary files /dev/null and b/backups/postgres-volume-backup.tar differ diff --git a/backups/volume-backup-log.txt b/backups/volume-backup-log.txt index 738e582..7d5a20b 100644 --- a/backups/volume-backup-log.txt +++ b/backups/volume-backup-log.txt @@ -1,24 +1,104 @@ -[2025-04-19_19-40-51] Starting volume backup for gitea-docker_postgres-data... -[2025-04-19_19-40-51] Creating backup to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-19_19-40-51.tar... -[2025-04-19_19-40-51] Volume backup failed! -[2025-04-19_19-41-05] Starting volume backup for gitea-docker_postgres-data... -[2025-04-19_19-41-05] Creating backup to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-19_19-41-05.tar... -[2025-04-19_19-41-05] Volume backup failed! -[2025-04-19_19-42-55] Starting volume backup for gitea-docker_postgres-data... -[2025-04-19_19-42-55] Creating backup to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-19_19-42-55.tar... -[2025-04-19_19-42-55] Volume backup completed successfully! -[2025-04-19_19-42-55] Compressing backup file... -[2025-04-19_19-42-55] Backup compressed to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-19_19-42-55.tar.zip -[2025-04-19_19-42-55] Backup copied to redundant location: D:\Pr00jects\gitea-docker\postgres-volume-backup-2025-04-19_19-42-55.tar.zip -[2025-04-19_19-43-53] Starting volume backup for gitea-docker_postgres-data... -[2025-04-19_19-43-53] Creating backup to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-19_19-43-53.tar... -[2025-04-19_19-43-53] Volume backup completed successfully! -[2025-04-19_19-43-53] Compressing backup file... -[2025-04-19_19-43-53] Backup compressed to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-19_19-43-53.tar.zip -[2025-04-19_19-43-53] Backup copied to redundant location: D:\Pr00jects\gitea-docker\postgres-volume-backup-2025-04-19_19-43-53.tar.zip -[2025-04-19_19-44-40] Starting volume backup for gitea-docker_postgres-data... -[2025-04-19_19-44-40] Creating backup to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-19_19-44-40.tar... -[2025-04-19_19-44-40] Volume backup completed successfully! -[2025-04-19_19-44-40] Compressing backup file... -[2025-04-19_19-44-40] Backup compressed to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-19_19-44-40.tar.zip -[2025-04-19_19-44-40] Backup copied to redundant location: D:\Pr00jects\gitea-docker\postgres-volume-backup-2025-04-19_19-44-40.tar.zip +[2025-04-19_19-40-51] Starting volume backup for gitea-docker_postgres-data... +[2025-04-19_19-40-51] Creating backup to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-19_19-40-51.tar... +[2025-04-19_19-40-51] Volume backup failed! +[2025-04-19_19-41-05] Starting volume backup for gitea-docker_postgres-data... +[2025-04-19_19-41-05] Creating backup to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-19_19-41-05.tar... +[2025-04-19_19-41-05] Volume backup failed! +[2025-04-19_19-42-55] Starting volume backup for gitea-docker_postgres-data... +[2025-04-19_19-42-55] Creating backup to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-19_19-42-55.tar... +[2025-04-19_19-42-55] Volume backup completed successfully! +[2025-04-19_19-42-55] Compressing backup file... +[2025-04-19_19-42-55] Backup compressed to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-19_19-42-55.tar.zip +[2025-04-19_19-42-55] Backup copied to redundant location: D:\Pr00jects\gitea-docker\postgres-volume-backup-2025-04-19_19-42-55.tar.zip +[2025-04-19_19-43-53] Starting volume backup for gitea-docker_postgres-data... +[2025-04-19_19-43-53] Creating backup to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-19_19-43-53.tar... +[2025-04-19_19-43-53] Volume backup completed successfully! +[2025-04-19_19-43-53] Compressing backup file... +[2025-04-19_19-43-53] Backup compressed to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-19_19-43-53.tar.zip +[2025-04-19_19-43-53] Backup copied to redundant location: D:\Pr00jects\gitea-docker\postgres-volume-backup-2025-04-19_19-43-53.tar.zip +[2025-04-19_19-44-40] Starting volume backup for gitea-docker_postgres-data... +[2025-04-19_19-44-40] Creating backup to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-19_19-44-40.tar... +[2025-04-19_19-44-40] Volume backup completed successfully! +[2025-04-19_19-44-40] Compressing backup file... +[2025-04-19_19-44-40] Backup compressed to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-19_19-44-40.tar.zip +[2025-04-19_19-44-40] Backup copied to redundant location: D:\Pr00jects\gitea-docker\postgres-volume-backup-2025-04-19_19-44-40.tar.zip +[2025-04-20_03-06-24] Starting volume backup for gitea-docker_postgres-data... +[2025-04-20_03-06-24] Creating backup to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-20_03-06-24.tar... +[2025-04-20_03-06-24] Volume backup completed successfully! +[2025-04-20_03-06-24] Compressing backup file... +[2025-04-20_03-06-24] Backup compressed to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-20_03-06-24.tar.zip +[2025-04-20_03-06-24] Backup copied to redundant location: D:\Pr00jects\gitea-docker\postgres-volume-backup-2025-04-20_03-06-24.tar.zip +[2025-04-21_03-05-47] Starting volume backup for gitea-docker_postgres-data... +[2025-04-21_03-05-47] Creating backup to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-21_03-05-47.tar... +[2025-04-21_03-05-47] Volume backup completed successfully! +[2025-04-21_03-05-47] Compressing backup file... +[2025-04-21_03-05-47] Backup compressed to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-21_03-05-47.tar.zip +[2025-04-21_03-05-47] Backup copied to redundant location: D:\Pr00jects\gitea-docker\postgres-volume-backup-2025-04-21_03-05-47.tar.zip +[2025-04-21_03-05-47] Removed old volume backup: postgres-volume-backup-2025-03-01_23-23-13.tar.zip +[2025-04-22_03-27-19] Starting volume backup for gitea-docker_postgres-data... +[2025-04-22_03-27-19] Creating backup to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-22_03-27-19.tar... +[2025-04-22_03-27-19] Volume backup completed successfully! +[2025-04-22_03-27-19] Compressing backup file... +[2025-04-22_03-27-19] Backup compressed to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-22_03-27-19.tar.zip +[2025-04-22_03-27-19] Backup copied to redundant location: D:\Pr00jects\gitea-docker\postgres-volume-backup-2025-04-22_03-27-19.tar.zip +[2025-04-22_03-27-19] Removed old volume backup: postgres-volume-backup-2025-04-19_19-42-55.tar.zip +[2025-04-23_08-10-53] Starting volume backup for gitea-docker_postgres-data... +[2025-04-23_08-10-53] Creating backup to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-23_08-10-53.tar... +[2025-04-23_08-10-53] Volume backup completed successfully! +[2025-04-23_08-10-53] Compressing backup file... +[2025-04-23_08-10-53] Backup compressed to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-04-23_08-10-53.tar.zip +[2025-04-23_08-10-53] Backup copied to redundant location: D:\Pr00jects\gitea-docker\postgres-volume-backup-2025-04-23_08-10-53.tar.zip +[2025-04-23_08-10-53] Removed old volume backup: postgres-volume-backup-2025-04-19_19-43-53.tar.zip +[2025-05-18_01-22-29] Starting volume backup for gitea-docker_postgres-data... +[2025-05-18_01-22-29] Creating backup to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-05-18_01-22-29.tar... +[2025-05-18_01-22-29] Volume backup completed successfully! +[2025-05-18_01-22-29] Compressing backup file... +[2025-05-18_01-22-29] Backup compressed to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-05-18_01-22-29.tar.zip +[2025-05-18_01-22-29] Backup copied to redundant location: D:\Pr00jects\gitea-docker\postgres-volume-backup-2025-05-18_01-22-29.tar.zip +[2025-05-18_01-22-29] Removed old volume backup: postgres-volume-backup-2025-04-19_19-44-40.tar.zip +[2025-05-18_03-00-14] Starting volume backup for gitea-docker_postgres-data... +[2025-05-18_03-00-14] Creating backup to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-05-18_03-00-14.tar... +[2025-05-18_03-00-14] Volume backup completed successfully! +[2025-05-18_03-00-14] Compressing backup file... +[2025-05-18_03-00-14] Backup compressed to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-05-18_03-00-14.tar.zip +[2025-05-18_03-00-14] Backup copied to redundant location: D:\Pr00jects\gitea-docker\postgres-volume-backup-2025-05-18_03-00-14.tar.zip +[2025-05-18_03-00-14] Removed old volume backup: postgres-volume-backup-2025-04-20_03-06-24.tar.zip +[2025-05-19_03-00-14] Starting volume backup for gitea-docker_postgres-data... +[2025-05-19_03-00-14] Creating backup to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-05-19_03-00-14.tar... +[2025-05-19_03-00-14] Volume backup completed successfully! +[2025-05-19_03-00-14] Compressing backup file... +[2025-05-19_03-00-14] Backup compressed to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-05-19_03-00-14.tar.zip +[2025-05-19_03-00-14] Backup copied to redundant location: D:\Pr00jects\gitea-docker\postgres-volume-backup-2025-05-19_03-00-14.tar.zip +[2025-05-19_03-00-14] Removed old volume backup: postgres-volume-backup-2025-04-21_03-05-47.tar.zip +[2025-05-20_03-14-23] Starting volume backup for gitea-docker_postgres-data... +[2025-05-20_03-14-23] Creating backup to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-05-20_03-14-23.tar... +[2025-05-20_03-14-23] Volume backup completed successfully! +[2025-05-20_03-14-23] Compressing backup file... +[2025-05-20_03-14-23] Backup compressed to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-05-20_03-14-23.tar.zip +[2025-05-20_03-14-23] Backup copied to redundant location: D:\Pr00jects\gitea-docker\postgres-volume-backup-2025-05-20_03-14-23.tar.zip +[2025-05-20_03-14-23] Removed old volume backup: postgres-volume-backup-2025-04-22_03-27-19.tar.zip +[2025-05-21_03-08-24] Starting volume backup for gitea-docker_postgres-data... +[2025-05-21_03-08-24] Creating backup to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-05-21_03-08-24.tar... +[2025-05-21_03-08-24] Volume backup completed successfully! +[2025-05-21_03-08-24] Compressing backup file... +[2025-05-21_03-08-24] Backup compressed to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-05-21_03-08-24.tar.zip +[2025-05-21_03-08-24] Backup copied to redundant location: D:\Pr00jects\gitea-docker\postgres-volume-backup-2025-05-21_03-08-24.tar.zip +[2025-05-21_03-08-24] Removed old volume backup: postgres-volume-backup-2025-04-23_08-10-53.tar.zip +[2025-05-22_03-03-49] Starting volume backup for gitea-docker_postgres-data... +[2025-05-22_03-03-49] Creating backup to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-05-22_03-03-49.tar... +[2025-05-22_03-03-49] Volume backup completed successfully! +[2025-05-22_03-03-49] Compressing backup file... +[2025-05-22_03-03-49] Backup compressed to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-05-22_03-03-49.tar.zip +[2025-05-22_03-03-49] Backup copied to redundant location: D:\Pr00jects\gitea-docker\postgres-volume-backup-2025-05-22_03-03-49.tar.zip +[2025-05-22_03-03-49] Removed old volume backup: postgres-volume-backup-2025-05-18_01-22-29.tar.zip +[2025-05-23_08-01-05] Starting volume backup for gitea-docker_postgres-data... +[2025-05-23_08-01-05] Creating backup to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-05-23_08-01-05.tar... +[2025-05-23_08-01-05] Volume backup completed successfully! +[2025-05-23_08-01-05] Compressing backup file... +[2025-06-09_21-30-15] Starting volume backup for gitea-docker_postgres-data... +[2025-06-09_21-30-15] Creating backup to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-06-09_21-30-15.tar... +[2025-06-09_21-30-15] Volume backup completed successfully! +[2025-06-09_21-30-15] Compressing backup file... +[2025-06-09_21-30-15] Backup compressed to C:\Users\benne\Projects\gitea-docker\backups\postgres-volume-backup-2025-06-09_21-30-15.tar.zip +[2025-06-09_21-30-15] Backup copied to redundant location: D:\Pr00jects\gitea-docker\postgres-volume-backup-2025-06-09_21-30-15.tar.zip +[2025-06-09_21-30-15] Removed old volume backup: postgres-volume-backup-2025-05-18_03-00-14.tar.zip diff --git a/docker-compose.headscale.yml b/docker-compose.headscale.yml new file mode 100644 index 0000000..62c36a0 --- /dev/null +++ b/docker-compose.headscale.yml @@ -0,0 +1,20 @@ +version: '3.8' + +services: + headscale: + image: headscale/headscale:latest + container_name: headscale + restart: unless-stopped + ports: + - "8081:8080" # Web UI and API (avoiding conflict with Traefik) + - "50443:50443" # gRPC + volumes: + - ./headscale/config:/etc/headscale + - ./headscale/data:/var/lib/headscale + command: serve + networks: + - headscale-net + +networks: + headscale-net: + driver: bridge diff --git a/docker-compose.yml b/docker-compose.yml index 1aa13ad..eb8bf9a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,6 +3,10 @@ version: "3" networks: gitea: external: false + traefik: + external: true + immich_default: + external: true volumes: gitea-data: @@ -15,18 +19,20 @@ services: container_name: traefik restart: always ports: - - "80:80" # HTTP - - "443:443" # HTTPS - - "8080:8080" # Dashboard + - "8080:80" # HTTP (changed from 80 to 8080 for ISP testing) + - "8443:443" # HTTPS (changed from 443 to 8443 for ISP testing) + - "8081:8080" # Dashboard (changed to avoid conflict) + networks: - gitea + - traefik volumes: - /var/run/docker.sock:/var/run/docker.sock:ro - traefik-certs:/letsencrypt command: - "--providers.docker=true" - "--providers.docker.exposedbydefault=false" - - "--providers.docker.network=gitea-docker_gitea" + - "--providers.docker.network=traefik" - "--entrypoints.web.address=:80" - "--entrypoints.websecure.address=:443" - "--entrypoints.web.http.redirections.entryPoint.to=websecure" @@ -53,7 +59,7 @@ services: - GITEA__database__PASSWD=gitea # Server Configuration - GITEA__server__DOMAIN=bee8333.ddns.net - - GITEA__server__ROOT_URL=https://bee8333.ddns.net/ + - GITEA__server__ROOT_URL=https://bee8333.ddns.net/gitea/ - GITEA__server__PROTOCOL=http - GITEA__server__HTTP_PORT=3000 - GITEA__server__SSH_DOMAIN=bee8333.ddns.net @@ -68,30 +74,63 @@ services: restart: always networks: - gitea + - traefik volumes: - gitea-data:/data - - /etc/timezone:/etc/timezone:ro - - /etc/localtime:/etc/localtime:ro +# - /etc/timezone:/etc/timezone:ro +# - /etc/localtime:/etc/localtime:ro ports: - "2224:22" # SSH: Host port 2224 -> Container port 22 depends_on: - db labels: - "traefik.enable=true" - # HTTP Configuration for HTTPS access - - "traefik.http.routers.gitea.rule=Host(`bee8333.ddns.net`)" + - "traefik.docker.network=traefik" + # HTTPS Configuration for /gitea subpath + - "traefik.http.routers.gitea.rule=Host(`bee8333.ddns.net`) && PathPrefix(`/gitea`)" - "traefik.http.routers.gitea.entrypoints=websecure" - "traefik.http.routers.gitea.tls.certresolver=letsencrypt" + - "traefik.http.routers.gitea.priority=10" - "traefik.http.services.gitea.loadbalancer.server.port=3000" + - "traefik.http.middlewares.gitea-stripprefix.stripprefix.prefixes=/gitea" - "traefik.http.middlewares.gitea-headers.headers.customrequestheaders.X-Forwarded-Proto=https" - - "traefik.http.routers.gitea.middlewares=gitea-headers@docker" + - "traefik.http.routers.gitea.middlewares=gitea-stripprefix@docker,gitea-headers@docker" # HTTP Configuration for HTTP -> HTTPS redirection - - "traefik.http.routers.gitea-http.rule=Host(`bee8333.ddns.net`)" + - "traefik.http.routers.gitea-http.rule=Host(`bee8333.ddns.net`) && PathPrefix(`/gitea`)" - "traefik.http.routers.gitea-http.entrypoints=web" - "traefik.http.middlewares.https-redirect.redirectscheme.scheme=https" - "traefik.http.middlewares.https-redirect.redirectscheme.permanent=true" - "traefik.http.routers.gitea-http.middlewares=https-redirect@docker" + headscale: + image: headscale/headscale:latest + container_name: headscale + restart: unless-stopped + ports: + - "3478:3478/udp" # STUN for DERP relay + volumes: + - ./headscale/config:/etc/headscale + - ./headscale/data:/var/lib/headscale + command: serve + networks: + - gitea + - traefik + labels: + - "traefik.enable=true" + - "traefik.docker.network=traefik" + # HTTPS Configuration for /headscale subpath + - "traefik.http.routers.headscale.rule=Host(`bee8333.ddns.net`) && PathPrefix(`/headscale`)" + - "traefik.http.routers.headscale.entrypoints=websecure" + - "traefik.http.routers.headscale.tls.certresolver=letsencrypt" + - "traefik.http.services.headscale.loadbalancer.server.port=8080" + - "traefik.http.middlewares.headscale-stripprefix.stripprefix.prefixes=/headscale" + - "traefik.http.middlewares.headscale-headers.headers.customrequestheaders.X-Forwarded-Proto=https" + - "traefik.http.routers.headscale.middlewares=headscale-stripprefix@docker,headscale-headers@docker" + # HTTP Configuration for HTTP -> HTTPS redirection + - "traefik.http.routers.headscale-http.rule=Host(`bee8333.ddns.net`) && PathPrefix(`/headscale`)" + - "traefik.http.routers.headscale-http.entrypoints=web" + - "traefik.http.routers.headscale-http.middlewares=https-redirect@docker" + db: image: postgres:14 container_name: gitea-db diff --git a/ensure-docker-running.ps1 b/ensure-docker-running.ps1 index 9b35ad1..c0ab8fb 100644 --- a/ensure-docker-running.ps1 +++ b/ensure-docker-running.ps1 @@ -1,83 +1,83 @@ -# Script to ensure Docker is running before scheduled backup -$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path -$logFile = Join-Path $scriptDir "backups\docker-status.log" -$timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss" - -# Ensure log directory exists -$backupDir = Join-Path $scriptDir "backups" -if (-not (Test-Path $backupDir)) { - New-Item -ItemType Directory -Path $backupDir -} - -"[$timestamp] Checking Docker status..." | Out-File -Append -FilePath $logFile - -# Check if Docker Desktop is running -$dockerProcess = Get-Process "Docker Desktop" -ErrorAction SilentlyContinue -if ($null -eq $dockerProcess) { - "[$timestamp] Docker Desktop is not running. Attempting to start..." | Out-File -Append -FilePath $logFile - - # Path to Docker Desktop - $dockerPath = "C:\Program Files\Docker\Docker\Docker Desktop.exe" - if (Test-Path $dockerPath) { - Start-Process $dockerPath - "[$timestamp] Started Docker Desktop." | Out-File -Append -FilePath $logFile - - # Wait for Docker to start up (give it 60 seconds) - $maxWaitTime = 60 - $waitTime = 0 - $dockerRunning = $false - - while (-not $dockerRunning -and $waitTime -lt $maxWaitTime) { - Start-Sleep -Seconds 5 - $waitTime += 5 - - try { - $dockerStatus = docker info 2>&1 - if ($LASTEXITCODE -eq 0) { - $dockerRunning = $true - "[$timestamp] Docker is now running after waiting $waitTime seconds." | Out-File -Append -FilePath $logFile - } - } catch { - # Keep waiting - } - } - - if (-not $dockerRunning) { - "[$timestamp] Docker did not start successfully after waiting $maxWaitTime seconds." | Out-File -Append -FilePath $logFile - } - } else { - "[$timestamp] Docker Desktop executable not found at expected location: $dockerPath" | Out-File -Append -FilePath $logFile - } -} else { - "[$timestamp] Docker Desktop is already running." | Out-File -Append -FilePath $logFile -} - -# Check if containers are running -try { - $containersRunning = docker ps 2>&1 - if ($LASTEXITCODE -eq 0) { - "[$timestamp] Docker containers status: " | Out-File -Append -FilePath $logFile - $runningContainers = docker ps --format "{{.Names}}" 2>&1 - $runningContainers | Out-File -Append -FilePath $logFile - - # Check specifically for gitea containers - $giteaRunning = $runningContainers | Select-String -Pattern "gitea" -Quiet - if (-not $giteaRunning) { - "[$timestamp] Gitea containers are not running. Starting containers..." | Out-File -Append -FilePath $logFile - - # Navigate to gitea-docker directory and start containers - Set-Location $scriptDir - docker-compose up -d 2>&1 | Out-File -Append -FilePath $logFile - - if ($LASTEXITCODE -eq 0) { - "[$timestamp] Successfully started Gitea containers." | Out-File -Append -FilePath $logFile - } else { - "[$timestamp] Failed to start Gitea containers." | Out-File -Append -FilePath $logFile - } - } - } else { - "[$timestamp] Failed to check running containers. Docker might not be ready yet." | Out-File -Append -FilePath $logFile - } -} catch { - "[$timestamp] Error checking Docker containers: $_" | Out-File -Append -FilePath $logFile +# Script to ensure Docker is running before scheduled backup +$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path +$logFile = Join-Path $scriptDir "backups\docker-status.log" +$timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss" + +# Ensure log directory exists +$backupDir = Join-Path $scriptDir "backups" +if (-not (Test-Path $backupDir)) { + New-Item -ItemType Directory -Path $backupDir +} + +"[$timestamp] Checking Docker status..." | Out-File -Append -FilePath $logFile + +# Check if Docker Desktop is running +$dockerProcess = Get-Process "Docker Desktop" -ErrorAction SilentlyContinue +if ($null -eq $dockerProcess) { + "[$timestamp] Docker Desktop is not running. Attempting to start..." | Out-File -Append -FilePath $logFile + + # Path to Docker Desktop + $dockerPath = "C:\Program Files\Docker\Docker\Docker Desktop.exe" + if (Test-Path $dockerPath) { + Start-Process $dockerPath + "[$timestamp] Started Docker Desktop." | Out-File -Append -FilePath $logFile + + # Wait for Docker to start up (give it 60 seconds) + $maxWaitTime = 60 + $waitTime = 0 + $dockerRunning = $false + + while (-not $dockerRunning -and $waitTime -lt $maxWaitTime) { + Start-Sleep -Seconds 5 + $waitTime += 5 + + try { + $dockerStatus = docker info 2>&1 + if ($LASTEXITCODE -eq 0) { + $dockerRunning = $true + "[$timestamp] Docker is now running after waiting $waitTime seconds." | Out-File -Append -FilePath $logFile + } + } catch { + # Keep waiting + } + } + + if (-not $dockerRunning) { + "[$timestamp] Docker did not start successfully after waiting $maxWaitTime seconds." | Out-File -Append -FilePath $logFile + } + } else { + "[$timestamp] Docker Desktop executable not found at expected location: $dockerPath" | Out-File -Append -FilePath $logFile + } +} else { + "[$timestamp] Docker Desktop is already running." | Out-File -Append -FilePath $logFile +} + +# Check if containers are running +try { + $containersRunning = docker ps 2>&1 + if ($LASTEXITCODE -eq 0) { + "[$timestamp] Docker containers status: " | Out-File -Append -FilePath $logFile + $runningContainers = docker ps --format "{{.Names}}" 2>&1 + $runningContainers | Out-File -Append -FilePath $logFile + + # Check specifically for gitea containers + $giteaRunning = $runningContainers | Select-String -Pattern "gitea" -Quiet + if (-not $giteaRunning) { + "[$timestamp] Gitea containers are not running. Starting containers..." | Out-File -Append -FilePath $logFile + + # Navigate to gitea-docker directory and start containers + Set-Location $scriptDir + docker-compose up -d 2>&1 | Out-File -Append -FilePath $logFile + + if ($LASTEXITCODE -eq 0) { + "[$timestamp] Successfully started Gitea containers." | Out-File -Append -FilePath $logFile + } else { + "[$timestamp] Failed to start Gitea containers." | Out-File -Append -FilePath $logFile + } + } + } else { + "[$timestamp] Failed to check running containers. Docker might not be ready yet." | Out-File -Append -FilePath $logFile + } +} catch { + "[$timestamp] Error checking Docker containers: $_" | Out-File -Append -FilePath $logFile } \ No newline at end of file diff --git a/gitea-dump.zip b/gitea-dump.zip new file mode 100644 index 0000000..46a6353 Binary files /dev/null and b/gitea-dump.zip differ diff --git a/gitea/conf/app.ini b/gitea/conf/app.ini index fc9409f..62731c0 100644 --- a/gitea/conf/app.ini +++ b/gitea/conf/app.ini @@ -1,37 +1,37 @@ -APP_NAME = BeeBrain -RUN_MODE = prod -RUN_USER = git - -[server] -DOMAIN = bee8333.ddns.net -SSH_DOMAIN = bee8333.ddns.net -HTTP_PORT = 3000 -ROOT_URL = https://bee8333.ddns.net/ -DISABLE_SSH = false -SSH_PORT = 222 -SSH_LISTEN_PORT = 22 -LFS_START_SERVER = true -PROTOCOL = https -CERT_FILE = /data/gitea/cert.pem -KEY_FILE = /data/gitea/key.pem - -[database] -DB_TYPE = postgres -HOST = db:5432 -NAME = gitea -USER = gitea -PASSWD = gitea -SSL_MODE = disable - -[repository] -ROOT = /data/git/repositories - -[security] -INSTALL_LOCK = true - -[service] -DISABLE_REGISTRATION = false -REQUIRE_SIGNIN_VIEW = true - -[indexer] +APP_NAME = BeeBrain +RUN_MODE = prod +RUN_USER = git + +[server] +DOMAIN = bee8333.ddns.net +SSH_DOMAIN = bee8333.ddns.net +HTTP_PORT = 3000 +ROOT_URL = https://bee8333.ddns.net/ +DISABLE_SSH = false +SSH_PORT = 222 +SSH_LISTEN_PORT = 22 +LFS_START_SERVER = true +PROTOCOL = https +CERT_FILE = /data/gitea/cert.pem +KEY_FILE = /data/gitea/key.pem + +[database] +DB_TYPE = postgres +HOST = db:5432 +NAME = gitea +USER = gitea +PASSWD = gitea +SSL_MODE = disable + +[repository] +ROOT = /data/git/repositories + +[security] +INSTALL_LOCK = true + +[service] +DISABLE_REGISTRATION = false +REQUIRE_SIGNIN_VIEW = true + +[indexer] ISSUE_INDEXER_PATH = /data/gitea/indexers/issues.bleve \ No newline at end of file diff --git a/headscale/config/config.yaml b/headscale/config/config.yaml new file mode 100644 index 0000000..3b8f3c1 --- /dev/null +++ b/headscale/config/config.yaml @@ -0,0 +1,54 @@ +server_url: https://bee8333.ddns.net/headscale/ +listen_addr: 0.0.0.0:8080 +metrics_listen_addr: 127.0.0.1:9090 +grpc_listen_addr: 0.0.0.0:50443 +grpc_allow_insecure: false + +tls_cert_path: "" +tls_key_path: "" + +private_key_path: /var/lib/headscale/private.key +noise: + private_key_path: /var/lib/headscale/noise_private.key + +prefixes: + v4: 100.64.0.0/10 + v6: fd7a:115c:a1e0::/48 + +derp: + server: + enabled: true + region_id: 900 + region_code: "homelab" + region_name: "Home Lab" + stun_listen_addr: "0.0.0.0:3478" + private_key_path: /var/lib/headscale/derp_server_private.key + urls: + - https://controlplane.tailscale.com/derpmap/default + +disable_check_updates: false +ephemeral_node_inactivity_timeout: 30m +database: + type: sqlite3 + sqlite: + path: /var/lib/headscale/db.sqlite + +log: + format: text + level: info + +policy: + path: "" + +dns: + override_local_dns: true + nameservers: + global: + - 1.1.1.1 + - 8.8.8.8 + search_domains: [] + magic_dns: true + base_domain: headscale.bee8333.local + +unix_socket: /var/run/headscale/headscale.sock +unix_socket_permission: "0770" diff --git a/immich-https.conf b/immich-https.conf new file mode 100644 index 0000000..1a98e64 --- /dev/null +++ b/immich-https.conf @@ -0,0 +1,36 @@ +events { + worker_connections 1024; +} + +http { + upstream immich { + server immich_server:2283; + } + + server { + listen 443 ssl; + server_name bee8333.ddns.net; + + # Self-signed SSL certificate (will be generated at startup) + ssl_certificate /etc/ssl/certs/immich.crt; + ssl_certificate_key /etc/ssl/private/immich.key; + ssl_protocols TLSv1.2 TLSv1.3; + ssl_ciphers HIGH:!aNULL:!MD5; + + client_max_body_size 50000M; + + # Direct proxy to Immich - NO subpath manipulation + location / { + proxy_pass http://immich; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto https; + + # WebSocket support for real-time features + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + } + } +} \ No newline at end of file diff --git a/immich-nginx.conf b/immich-nginx.conf new file mode 100644 index 0000000..394ef1f --- /dev/null +++ b/immich-nginx.conf @@ -0,0 +1,49 @@ +events { + worker_connections 1024; +} + +http { + upstream immich { + server immich_server:2283; + } + + server { + listen 80; + server_name bee8333.ddns.net; + + client_max_body_size 50000M; + + # Main application - all requests go to Immich + location / { + proxy_pass http://immich; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + # Critical headers for subpath handling + proxy_set_header X-Forwarded-Prefix /immich; + proxy_set_header X-Script-Name /immich; + + # WebSocket support for real-time features + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + + # SPA support - handle client-side routing + proxy_intercept_errors on; + error_page 404 = @fallback; + } + + # Fallback for SPA routing + location @fallback { + proxy_pass http://immich; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Prefix /immich; + proxy_set_header X-Script-Name /immich; + } + } +} \ No newline at end of file diff --git a/ob.md b/ob.md index 7c7ffa0..df89e0a 100644 --- a/ob.md +++ b/ob.md @@ -1,125 +1,125 @@ -# Setting Up Git Access with Gitea and Obsidian - -## Part 1: Authorizing Git Client Access - -### Prerequisites -- Gitea instance accessible through your domain (bee8333.ddns.net) via HTTPS -- Administrative privileges for initial setup - -### Repository Setup -- For new repositories using HTTPS: -```bash -git clone https://bee8333.ddns.net:3000/username/repository.git -``` - -- For new repositories using SSH: -```bash -git clone ssh://git@bee8333.ddns.net:222/username/repository.git -``` - -- For existing repositories (HTTPS): -```bash -git remote set-url origin https://bee8333.ddns.net:3000/username/repository.git -``` - -- For existing repositories (SSH): -```bash -git remote set-url origin ssh://git@bee8333.ddns.net:222/username/repository.git -``` - -### Authentication -When using HTTPS: -1. You'll be prompted for your Gitea username and password -2. For better security, create a Personal Access Token in Gitea: - - Go to Settings → Applications → Generate New Token - - Give it a description - - Copy the token immediately (it won't be shown again) - - Use this token as your password when Git asks for credentials - -When using SSH: -1. Generate an SSH key pair if you haven't already: - ```bash - ssh-keygen -t ed25519 -C "your_email@example.com" - ``` -2. Add your public key to Gitea: - - Go to Settings → SSH / GPG Keys - - Click "Add Key" - - Paste your public key (from ~/.ssh/id_ed25519.pub) -3. SSH will use your key automatically for authentication - -### Important Note -When using non-standard HTTPS ports (like 3000): -1. Use an elevated (Administrator) PowerShell/Command Prompt for Git operations -2. Regular terminals in VS Code/Cursor may not have sufficient privileges -3. If Git operations fail, try running your terminal as Administrator - -## Part 2: Obsidian-Git Integration - -### Plugin Installation -1. Open Obsidian Settings → Community plugins -2. Search for "Obsidian Git" -3. Install and enable the plugin - -### Plugin Configuration -1. Go to Settings → Community plugins → Obsidian Git -2. Recommended settings: - - ❌ Auto pull interval (disable when using Syncthing) - - ✅ Show status bar - - ✅ Source Control View - - ✅ Show changes files count in status bar - - Configure default commit message - -### Essential Commands -Access these via Command Palette (Ctrl/Cmd + P): -- `Open source control view` - View changes and branch info -- `List changed files` - See modifications -- `View diff` - Check file changes -- `Stage/Unstage current file` - Prepare for commit -- `Commit staged` - Save staged changes -- `Create/Switch branch` - Branch management - -### Recommended Workflow -1. Make changes in Obsidian -2. Check Source Control View -3. Stage desired files -4. Commit with meaningful message -5. Push to Gitea - -### Status Bar Features -- Current branch name -- Number of changed files -- Sync status indicators - -## Important Configuration - -### Gitignore Setup -Add these patterns to `.gitignore`: -``` -.trash/ -.stversions/ -.obsidian/workspace.json -.obsidian/workspace-mobile.json -``` - -### Security Best Practices -- Keep SSH private keys secure -- Use strong SSH key passphrases -- Regularly review and clean up SSH keys in Gitea -- Never share private keys - -### Syncthing Compatibility -- Wait for Syncthing sync before Git operations -- Commit/push before closing Obsidian -- Ensure `.stversions` is in `.gitignore` - -### Performance Tips -- Stage files individually -- Use branches for major changes -- Commit regularly, push selectively -- Monitor Source Control View - -## Collaboration Guidelines -- Pull before making changes -- Use branches for significant changes -- Check diff view for conflicts +# Setting Up Git Access with Gitea and Obsidian + +## Part 1: Authorizing Git Client Access + +### Prerequisites +- Gitea instance accessible through your domain (bee8333.ddns.net) via HTTPS +- Administrative privileges for initial setup + +### Repository Setup +- For new repositories using HTTPS: +```bash +git clone https://bee8333.ddns.net:3000/username/repository.git +``` + +- For new repositories using SSH: +```bash +git clone ssh://git@bee8333.ddns.net:222/username/repository.git +``` + +- For existing repositories (HTTPS): +```bash +git remote set-url origin https://bee8333.ddns.net:3000/username/repository.git +``` + +- For existing repositories (SSH): +```bash +git remote set-url origin ssh://git@bee8333.ddns.net:222/username/repository.git +``` + +### Authentication +When using HTTPS: +1. You'll be prompted for your Gitea username and password +2. For better security, create a Personal Access Token in Gitea: + - Go to Settings → Applications → Generate New Token + - Give it a description + - Copy the token immediately (it won't be shown again) + - Use this token as your password when Git asks for credentials + +When using SSH: +1. Generate an SSH key pair if you haven't already: + ```bash + ssh-keygen -t ed25519 -C "your_email@example.com" + ``` +2. Add your public key to Gitea: + - Go to Settings → SSH / GPG Keys + - Click "Add Key" + - Paste your public key (from ~/.ssh/id_ed25519.pub) +3. SSH will use your key automatically for authentication + +### Important Note +When using non-standard HTTPS ports (like 3000): +1. Use an elevated (Administrator) PowerShell/Command Prompt for Git operations +2. Regular terminals in VS Code/Cursor may not have sufficient privileges +3. If Git operations fail, try running your terminal as Administrator + +## Part 2: Obsidian-Git Integration + +### Plugin Installation +1. Open Obsidian Settings → Community plugins +2. Search for "Obsidian Git" +3. Install and enable the plugin + +### Plugin Configuration +1. Go to Settings → Community plugins → Obsidian Git +2. Recommended settings: + - ❌ Auto pull interval (disable when using Syncthing) + - ✅ Show status bar + - ✅ Source Control View + - ✅ Show changes files count in status bar + - Configure default commit message + +### Essential Commands +Access these via Command Palette (Ctrl/Cmd + P): +- `Open source control view` - View changes and branch info +- `List changed files` - See modifications +- `View diff` - Check file changes +- `Stage/Unstage current file` - Prepare for commit +- `Commit staged` - Save staged changes +- `Create/Switch branch` - Branch management + +### Recommended Workflow +1. Make changes in Obsidian +2. Check Source Control View +3. Stage desired files +4. Commit with meaningful message +5. Push to Gitea + +### Status Bar Features +- Current branch name +- Number of changed files +- Sync status indicators + +## Important Configuration + +### Gitignore Setup +Add these patterns to `.gitignore`: +``` +.trash/ +.stversions/ +.obsidian/workspace.json +.obsidian/workspace-mobile.json +``` + +### Security Best Practices +- Keep SSH private keys secure +- Use strong SSH key passphrases +- Regularly review and clean up SSH keys in Gitea +- Never share private keys + +### Syncthing Compatibility +- Wait for Syncthing sync before Git operations +- Commit/push before closing Obsidian +- Ensure `.stversions` is in `.gitignore` + +### Performance Tips +- Stage files individually +- Use branches for major changes +- Commit regularly, push selectively +- Monitor Source Control View + +## Collaboration Guidelines +- Pull before making changes +- Use branches for significant changes +- Check diff view for conflicts - Let Syncthing sync complete before Git operations \ No newline at end of file diff --git a/restore-gitea-db.ps1 b/restore-gitea-db.ps1 index 4dd49ae..8b1e98b 100644 --- a/restore-gitea-db.ps1 +++ b/restore-gitea-db.ps1 @@ -1,67 +1,67 @@ -# Gitea Database Restore Script -param ( - [Parameter(Mandatory=$true)] - [string]$BackupFile -) - -# Check if backup file exists -if (-not (Test-Path $BackupFile)) { - Write-Host "Backup file not found: $BackupFile" -ForegroundColor Red - exit 1 -} - -# Extract the backup if it's a zip file -$tempFile = $null -if ($BackupFile.EndsWith(".zip")) { - $tempDir = [System.IO.Path]::GetTempPath() - $tempFile = Join-Path $tempDir "gitea-db-restore-temp.sql" - - Write-Host "Extracting backup file..." - Expand-Archive -Path $BackupFile -DestinationPath $tempDir -Force - $extractedFile = Get-ChildItem -Path $tempDir -Filter "*.sql" | Select-Object -First 1 - - if ($extractedFile) { - Copy-Item $extractedFile.FullName -Destination $tempFile - $BackupFile = $tempFile - } else { - Write-Host "Failed to extract SQL file from backup" -ForegroundColor Red - exit 1 - } -} - -# Confirm before proceeding -Write-Host "WARNING: This will overwrite the current database with the backup." -ForegroundColor Yellow -Write-Host "Make sure your Gitea service is stopped before proceeding." -ForegroundColor Yellow -$confirmation = Read-Host "Do you want to continue? (y/n)" - -if ($confirmation -ne "y") { - Write-Host "Restore cancelled." - if ($tempFile -and (Test-Path $tempFile)) { - Remove-Item $tempFile - } - exit 0 -} - -# Stop Gitea services -Write-Host "Stopping Gitea services..." -docker-compose stop - -# Restore the database -Write-Host "Restoring database from backup..." -Get-Content $BackupFile | docker exec -i gitea-db psql -U gitea -d gitea - -# Check restore status -if ($LASTEXITCODE -eq 0) { - Write-Host "Database restore completed successfully!" -ForegroundColor Green -} else { - Write-Host "Database restore failed!" -ForegroundColor Red -} - -# Clean up temp file if created -if ($tempFile -and (Test-Path $tempFile)) { - Remove-Item $tempFile -} - -# Restart Gitea services -Write-Host "Starting Gitea services..." +# Gitea Database Restore Script +param ( + [Parameter(Mandatory=$true)] + [string]$BackupFile +) + +# Check if backup file exists +if (-not (Test-Path $BackupFile)) { + Write-Host "Backup file not found: $BackupFile" -ForegroundColor Red + exit 1 +} + +# Extract the backup if it's a zip file +$tempFile = $null +if ($BackupFile.EndsWith(".zip")) { + $tempDir = [System.IO.Path]::GetTempPath() + $tempFile = Join-Path $tempDir "gitea-db-restore-temp.sql" + + Write-Host "Extracting backup file..." + Expand-Archive -Path $BackupFile -DestinationPath $tempDir -Force + $extractedFile = Get-ChildItem -Path $tempDir -Filter "*.sql" | Select-Object -First 1 + + if ($extractedFile) { + Copy-Item $extractedFile.FullName -Destination $tempFile + $BackupFile = $tempFile + } else { + Write-Host "Failed to extract SQL file from backup" -ForegroundColor Red + exit 1 + } +} + +# Confirm before proceeding +Write-Host "WARNING: This will overwrite the current database with the backup." -ForegroundColor Yellow +Write-Host "Make sure your Gitea service is stopped before proceeding." -ForegroundColor Yellow +$confirmation = Read-Host "Do you want to continue? (y/n)" + +if ($confirmation -ne "y") { + Write-Host "Restore cancelled." + if ($tempFile -and (Test-Path $tempFile)) { + Remove-Item $tempFile + } + exit 0 +} + +# Stop Gitea services +Write-Host "Stopping Gitea services..." +docker-compose stop + +# Restore the database +Write-Host "Restoring database from backup..." +Get-Content $BackupFile | docker exec -i gitea-db psql -U gitea -d gitea + +# Check restore status +if ($LASTEXITCODE -eq 0) { + Write-Host "Database restore completed successfully!" -ForegroundColor Green +} else { + Write-Host "Database restore failed!" -ForegroundColor Red +} + +# Clean up temp file if created +if ($tempFile -and (Test-Path $tempFile)) { + Remove-Item $tempFile +} + +# Restart Gitea services +Write-Host "Starting Gitea services..." docker-compose start \ No newline at end of file diff --git a/restore-volume.ps1 b/restore-volume.ps1 index 913b003..1365f3b 100644 --- a/restore-volume.ps1 +++ b/restore-volume.ps1 @@ -1,88 +1,88 @@ -# Script to restore the Postgres Docker volume from a backup -param ( - [Parameter(Mandatory=$true)] - [string]$BackupFile -) - -$volumeName = "gitea-docker_postgres-data" -$tempDir = Join-Path $env:TEMP "postgres-volume-restore" - -# Check if backup file exists -if (-not (Test-Path $BackupFile)) { - Write-Host "Backup file not found: $BackupFile" -ForegroundColor Red - exit 1 -} - -# Extract the backup if it's a zip file -$tarFile = $BackupFile -if ($BackupFile.EndsWith(".zip")) { - # Create temp directory if it doesn't exist - if (-not (Test-Path $tempDir)) { - New-Item -ItemType Directory -Path $tempDir -Force | Out-Null - } else { - # Clean temp directory - Remove-Item -Path "$tempDir\*" -Force -Recurse -ErrorAction SilentlyContinue - } - - Write-Host "Extracting backup file..." - Expand-Archive -Path $BackupFile -DestinationPath $tempDir -Force - $extractedFile = Get-ChildItem -Path $tempDir -Filter "*.tar" | Select-Object -First 1 - - if ($extractedFile) { - $tarFile = $extractedFile.FullName - } else { - Write-Host "Failed to extract TAR file from backup" -ForegroundColor Red - exit 1 - } -} - -# Confirm before proceeding -Write-Host "WARNING: This will overwrite the current database volume with the backup." -ForegroundColor Yellow -Write-Host "Make sure your Gitea services are stopped before proceeding." -ForegroundColor Yellow -$confirmation = Read-Host "Do you want to continue? (y/n)" - -if ($confirmation -ne "y") { - Write-Host "Restore cancelled." - exit 0 -} - -# Stop Gitea services -Write-Host "Stopping Gitea services..." -docker-compose down - -# Check if volume exists and remove it -$volumeExists = docker volume ls --format "{{.Name}}" | Select-String -Pattern "^$volumeName$" -if ($volumeExists) { - Write-Host "Removing existing volume $volumeName..." - docker volume rm $volumeName - if ($LASTEXITCODE -ne 0) { - Write-Host "Failed to remove existing volume. It might be in use by another container." -ForegroundColor Red - exit 1 - } -} - -# Create a new volume -Write-Host "Creating new volume $volumeName..." -docker volume create $volumeName - -# Restore from backup -Write-Host "Restoring volume from backup..." -docker run --rm -v ${volumeName}:/volume -v ${tarFile}:/backup.tar alpine sh -c "cd /volume && tar -xf /backup.tar" - -if ($LASTEXITCODE -eq 0) { - Write-Host "Volume restore completed successfully!" -ForegroundColor Green -} else { - Write-Host "Volume restore failed!" -ForegroundColor Red - exit 1 -} - -# Clean up temp directory if created -if ($BackupFile.EndsWith(".zip") -and (Test-Path $tempDir)) { - Remove-Item -Path $tempDir -Force -Recurse -ErrorAction SilentlyContinue -} - -# Start Gitea services -Write-Host "Starting Gitea services..." -docker-compose up -d - +# Script to restore the Postgres Docker volume from a backup +param ( + [Parameter(Mandatory=$true)] + [string]$BackupFile +) + +$volumeName = "gitea-docker_postgres-data" +$tempDir = Join-Path $env:TEMP "postgres-volume-restore" + +# Check if backup file exists +if (-not (Test-Path $BackupFile)) { + Write-Host "Backup file not found: $BackupFile" -ForegroundColor Red + exit 1 +} + +# Extract the backup if it's a zip file +$tarFile = $BackupFile +if ($BackupFile.EndsWith(".zip")) { + # Create temp directory if it doesn't exist + if (-not (Test-Path $tempDir)) { + New-Item -ItemType Directory -Path $tempDir -Force | Out-Null + } else { + # Clean temp directory + Remove-Item -Path "$tempDir\*" -Force -Recurse -ErrorAction SilentlyContinue + } + + Write-Host "Extracting backup file..." + Expand-Archive -Path $BackupFile -DestinationPath $tempDir -Force + $extractedFile = Get-ChildItem -Path $tempDir -Filter "*.tar" | Select-Object -First 1 + + if ($extractedFile) { + $tarFile = $extractedFile.FullName + } else { + Write-Host "Failed to extract TAR file from backup" -ForegroundColor Red + exit 1 + } +} + +# Confirm before proceeding +Write-Host "WARNING: This will overwrite the current database volume with the backup." -ForegroundColor Yellow +Write-Host "Make sure your Gitea services are stopped before proceeding." -ForegroundColor Yellow +$confirmation = Read-Host "Do you want to continue? (y/n)" + +if ($confirmation -ne "y") { + Write-Host "Restore cancelled." + exit 0 +} + +# Stop Gitea services +Write-Host "Stopping Gitea services..." +docker-compose down + +# Check if volume exists and remove it +$volumeExists = docker volume ls --format "{{.Name}}" | Select-String -Pattern "^$volumeName$" +if ($volumeExists) { + Write-Host "Removing existing volume $volumeName..." + docker volume rm $volumeName + if ($LASTEXITCODE -ne 0) { + Write-Host "Failed to remove existing volume. It might be in use by another container." -ForegroundColor Red + exit 1 + } +} + +# Create a new volume +Write-Host "Creating new volume $volumeName..." +docker volume create $volumeName + +# Restore from backup +Write-Host "Restoring volume from backup..." +docker run --rm -v ${volumeName}:/volume -v ${tarFile}:/backup.tar alpine sh -c "cd /volume && tar -xf /backup.tar" + +if ($LASTEXITCODE -eq 0) { + Write-Host "Volume restore completed successfully!" -ForegroundColor Green +} else { + Write-Host "Volume restore failed!" -ForegroundColor Red + exit 1 +} + +# Clean up temp directory if created +if ($BackupFile.EndsWith(".zip") -and (Test-Path $tempDir)) { + Remove-Item -Path $tempDir -Force -Recurse -ErrorAction SilentlyContinue +} + +# Start Gitea services +Write-Host "Starting Gitea services..." +docker-compose up -d + Write-Host "Restore process completed. Check if your Gitea instance is working properly." -ForegroundColor Green \ No newline at end of file diff --git a/run-backup.ps1 b/run-backup.ps1 index 96c8aac..8533e8e 100644 --- a/run-backup.ps1 +++ b/run-backup.ps1 @@ -1,17 +1,17 @@ -# This script is automatically generated - do not edit manually -# It runs the Docker check script followed by database and volume backup scripts - -# Get the script directory -$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path - -# Run the Docker check script first -$dockerCheckScript = Join-Path $scriptDir "ensure-docker-running.ps1" -& $dockerCheckScript - -# Then run the database backup script -$dbBackupScript = Join-Path $scriptDir "backup-gitea-db.ps1" -& $dbBackupScript - -# Finally run the volume backup script -$volumeBackupScript = Join-Path $scriptDir "backup-volume.ps1" -& $volumeBackupScript +# This script is automatically generated - do not edit manually +# It runs the Docker check script followed by database and volume backup scripts + +# Get the script directory +$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path + +# Run the Docker check script first +$dockerCheckScript = Join-Path $scriptDir "ensure-docker-running.ps1" +& $dockerCheckScript + +# Then run the database backup script +$dbBackupScript = Join-Path $scriptDir "backup-gitea-db.ps1" +& $dbBackupScript + +# Finally run the volume backup script +$volumeBackupScript = Join-Path $scriptDir "backup-volume.ps1" +& $volumeBackupScript diff --git a/schedule-backup.ps1 b/schedule-backup.ps1 index c18d8cb..95ea0b0 100644 --- a/schedule-backup.ps1 +++ b/schedule-backup.ps1 @@ -1,67 +1,67 @@ -# Script to create a scheduled task for Gitea database backups -$workingDir = Split-Path -Parent $MyInvocation.MyCommand.Path -$scriptPath = Join-Path $workingDir "backup-gitea-db.ps1" -$dockerCheckScript = Join-Path $workingDir "ensure-docker-running.ps1" -$taskName = "GiteaDatabaseBackup" -$taskDescription = "Regular backup of Gitea PostgreSQL database" - -# Check if the backup script exists -if (-not (Test-Path $scriptPath)) { - Write-Host "Backup script not found at: $scriptPath" -ForegroundColor Red - exit 1 -} - -# Check if the Docker check script exists -if (-not (Test-Path $dockerCheckScript)) { - Write-Host "Docker check script not found at: $dockerCheckScript" -ForegroundColor Red - exit 1 -} - -# Create a batch script that runs both scripts -$batchScriptPath = Join-Path $workingDir "run-backup.ps1" -@" -# This script is automatically generated - do not edit manually -# It runs the Docker check script followed by the backup script - -# Get the script directory -`$scriptDir = Split-Path -Parent `$MyInvocation.MyCommand.Path - -# Run the Docker check script first -`$dockerCheckScript = Join-Path `$scriptDir "ensure-docker-running.ps1" -& `$dockerCheckScript - -# Then run the backup script -`$backupScript = Join-Path `$scriptDir "backup-gitea-db.ps1" -& `$backupScript -"@ | Out-File -FilePath $batchScriptPath -Encoding utf8 - -# Create a scheduled task to run daily at 3 AM -$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$batchScriptPath`"" -WorkingDirectory "$workingDir" -$trigger = New-ScheduledTaskTrigger -Daily -At 3AM -$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -DontStopOnIdleEnd -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries - -# Create a principal that runs with highest privileges -$principal = New-ScheduledTaskPrincipal -UserId "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount -RunLevel Highest - -# Register the scheduled task -$taskExists = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue - -if ($taskExists) { - Write-Host "Task '$taskName' already exists. Updating..." -ForegroundColor Yellow - # Get the existing task - $task = Get-ScheduledTask -TaskName $taskName - # Update the task properties - $task.Actions = $action - $task.Triggers = $trigger - $task.Settings = $settings - $task.Principal = $principal - $task.Description = $taskDescription - # Save the updated task - Set-ScheduledTask -InputObject $task -} else { - Write-Host "Creating new scheduled task '$taskName'..." -ForegroundColor Green - Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Settings $settings -Description $taskDescription -Principal $principal -} - -Write-Host "Scheduled task setup complete. The database will be backed up daily at 3 AM." -ForegroundColor Green +# Script to create a scheduled task for Gitea database backups +$workingDir = Split-Path -Parent $MyInvocation.MyCommand.Path +$scriptPath = Join-Path $workingDir "backup-gitea-db.ps1" +$dockerCheckScript = Join-Path $workingDir "ensure-docker-running.ps1" +$taskName = "GiteaDatabaseBackup" +$taskDescription = "Regular backup of Gitea PostgreSQL database" + +# Check if the backup script exists +if (-not (Test-Path $scriptPath)) { + Write-Host "Backup script not found at: $scriptPath" -ForegroundColor Red + exit 1 +} + +# Check if the Docker check script exists +if (-not (Test-Path $dockerCheckScript)) { + Write-Host "Docker check script not found at: $dockerCheckScript" -ForegroundColor Red + exit 1 +} + +# Create a batch script that runs both scripts +$batchScriptPath = Join-Path $workingDir "run-backup.ps1" +@" +# This script is automatically generated - do not edit manually +# It runs the Docker check script followed by the backup script + +# Get the script directory +`$scriptDir = Split-Path -Parent `$MyInvocation.MyCommand.Path + +# Run the Docker check script first +`$dockerCheckScript = Join-Path `$scriptDir "ensure-docker-running.ps1" +& `$dockerCheckScript + +# Then run the backup script +`$backupScript = Join-Path `$scriptDir "backup-gitea-db.ps1" +& `$backupScript +"@ | Out-File -FilePath $batchScriptPath -Encoding utf8 + +# Create a scheduled task to run daily at 3 AM +$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$batchScriptPath`"" -WorkingDirectory "$workingDir" +$trigger = New-ScheduledTaskTrigger -Daily -At 3AM +$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -DontStopOnIdleEnd -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries + +# Create a principal that runs with highest privileges +$principal = New-ScheduledTaskPrincipal -UserId "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount -RunLevel Highest + +# Register the scheduled task +$taskExists = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue + +if ($taskExists) { + Write-Host "Task '$taskName' already exists. Updating..." -ForegroundColor Yellow + # Get the existing task + $task = Get-ScheduledTask -TaskName $taskName + # Update the task properties + $task.Actions = $action + $task.Triggers = $trigger + $task.Settings = $settings + $task.Principal = $principal + $task.Description = $taskDescription + # Save the updated task + Set-ScheduledTask -InputObject $task +} else { + Write-Host "Creating new scheduled task '$taskName'..." -ForegroundColor Green + Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Settings $settings -Description $taskDescription -Principal $principal +} + +Write-Host "Scheduled task setup complete. The database will be backed up daily at 3 AM." -ForegroundColor Green Write-Host "Backup files will be stored in the 'backups' folder in your Gitea Docker directory." -ForegroundColor Green \ No newline at end of file