Skip to content

mavstuff/SimpleDBBackup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleDBBackup

Cross-platform database backup utility for SQL Server and PostgreSQL, built on .NET 10. Runs on Windows and Linux (cron/systemd).

Features

  • Scheduled backups of one or more databases
  • ZIP compression after each backup
  • Automatic deletion of backups older than N days
  • Optional FTP mirror upload
  • Single-instance lock (prevents overlapping runs)

Requirements

  • .NET 10 runtime
  • SQL Server: reachable instance; BACKUP DATABASE path must be valid on the SQL Server host (local or remote)
  • PostgreSQL: pg_dump in PATH (Linux: postgresql-client package; Windows: PostgreSQL install bin folder)

Configuration

Edit appsettings.json next to the executable.

SQL Server (default)

Each entry in ConnectionStrings is a full connection string with Database (or Initial Catalog) set to the database to back up. Use separate entries for different servers or credentials.

{
  "DatabaseProvider": "SqlServer",
  "ConnectionStrings": [
    "Server=localhost;Database=shop;User Id=sa;Password=YourPassword;TrustServerCertificate=True",
    "Server=localhost;Database=frontend;User Id=sa;Password=YourPassword;TrustServerCertificate=True",
    "Server=remote;Database=accounting;User Id=sa;Password=YourPassword;TrustServerCertificate=True"
  ],
  "BackupDir": "C:\\DB_Backups",
  "DeletionDays": 10
}

On Linux, use SQL authentication (Integrated Security is Windows-specific) and a path the SQL Server process can write, for example /var/opt/mssql/backup when SQL Server runs locally.

PostgreSQL

{
  "DatabaseProvider": "PostgreSQL",
  "ConnectionStrings": [
    "Host=localhost;Port=5432;Username=postgres;Password=secret;Database=shop",
    "Host=localhost;Port=5432;Username=postgres;Password=secret;Database=frontend"
  ],
  "BackupDir": "/var/db_backups",
  "DeletionDays": 10,
  "PgDumpPath": "pg_dump"
}

pg_dump writes the dump file on the machine where this tool runs (unlike SQL Server BACKUP TO DISK, which uses the server filesystem).

FTP (optional)

{
  "FtpServer": "ftp.example.com",
  "FtpLogin": "user",
  "FtpPassword": "password",
  "FtpUploadDir": "/backups"
}

Build and run

dotnet build -c Release
dotnet run -c Release --project SimpleDBBackup

Published self-contained example for Linux x64:

dotnet publish SimpleDBBackup -c Release -r linux-x64 --self-contained

Scheduling

Windows: Task Scheduler — run SimpleDBBackup.exe on your schedule.

Linux (cron, daily at 2:00):

0 2 * * * /usr/local/bin/SimpleDBBackup >> /var/log/simpledbbackup.log 2>&1

Use a dedicated backup directory only for this tool; files older than DeletionDays are removed from that folder.

Restore notes

  • SQL Server: restore from extracted .bak via SSMS or RESTORE DATABASE
  • PostgreSQL: pg_restore -d dbname backup.dump (custom format from pg_dump -Fc)

About

Simple SQL Server database backup utility

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages