Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ web/node_modules/
# Build artifacts
server/bin/
web/dist/
.build-tmp/

# Data & logs
data/
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ desktop.ini
*~
.claude/
.codex/
.build-tmp/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

| Capability | Details |
|-----------|---------|
| **Backup Types** | Files/directories (multi-source), MySQL, PostgreSQL, SQLite, SAP HANA (full / incremental / differential / log + parallel channels + retry) |
| **Backup Types** | Files/directories (multi-source), MySQL, PostgreSQL, SQLite, SQL Server (VDI; Linux/Windows worker), SAP HANA (full / incremental / differential / log + parallel channels + retry) |
| **SAP HANA Backint Agent** | Built-in Backint protocol — HANA's native interface routes data directly to any BackupX storage backend |
| **70+ Storage Backends** | Alibaba OSS, Tencent COS, Qiniu, S3, Google Drive, WebDAV, FTP + SFTP, Azure Blob, Dropbox, OneDrive and dozens more via rclone |
| **Scheduling** | Cron + visual editor + auto-retention (by days/count + empty-directory cleanup) |
Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

| 能力 | 说明 |
|------|------|
| **备份类型** | 文件/目录(多源路径)、MySQL、PostgreSQL、SQLite、SAP HANA(完整/增量/差异/日志备份 + 并行通道 + 失败重试) |
| **备份类型** | 文件/目录(多源路径)、MySQL、PostgreSQL、SQLite、SQL Server(VDI,需 Linux/Windows 原生组件)、SAP HANA(完整/增量/差异/日志备份 + 并行通道 + 失败重试) |
| **SAP HANA Backint 代理** | 内置 SAP HANA Backint 协议代理,HANA 原生备份接口可直接把数据路由到 BackupX 支持的任意存储后端 |
| **70+ 存储后端** | 内置阿里云 OSS / 腾讯云 COS / 七牛云 / S3 / Google Drive / WebDAV / FTP + 通过 rclone 集成 SFTP、Azure Blob、Dropbox、OneDrive 等 70+ 后端 |
| **自动调度** | Cron 定时 + 可视化编辑器 + 自动保留策略(按天数/份数清理,自动回收空目录) |
Expand Down
8 changes: 6 additions & 2 deletions docs-site/docs/features/backup-types.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
sidebar_position: 1
title: Backup Types
description: File, MySQL, PostgreSQL, SQLite and SAP HANA — what they back up and what to configure.
description: File, MySQL, PostgreSQL, SQLite, SQL Server and SAP HANA — what they back up and what to configure.
---

# Backup Types

BackupX supports five built-in backup types. Type determines which runner executes the job.
BackupX supports the following built-in backup types. Type determines which runner executes the job.

When a task is routed to a remote Agent, the source tools and paths are resolved on that Agent host. Multi-target uploads are still tracked per storage target; if at least one target succeeds, the backup record is marked successful and the per-target result table shows partial failures.

Expand Down Expand Up @@ -52,3 +52,7 @@ Two modes are supported — see the dedicated [SAP HANA](./sap-hana) page.
## Deletion behavior

When a task is deleted, BackupX removes backup artifacts from every storage target but preserves backup records for audit. Task deletion also tears down the cron schedule entry.

## SQL Server (VDI)

[SQL Server VDI](./sql-server) requires a native worker on the database host; supports Linux and Windows COPY_ONLY full backups.
101 changes: 101 additions & 0 deletions docs-site/docs/features/sql-server.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
sidebar_position: 4
title: SQL Server VDI
description: Native SQL Server full backups on Linux and Windows through a local VDI worker.
---

# SQL Server VDI

SQL Server tasks create a native `.bak` with `BACKUP DATABASE ... WITH COPY_ONLY, CHECKSUM`. COPY_ONLY preserves an existing differential backup base. Each task handles one database; `tempdb`, differential backups and transaction-log backups are not supported in this implementation.

The Master can run on a different machine. The **execution node and `backupx-sqlvdi` worker must share the SQL Server host and its shared-memory environment**. Bind the task to that specific Agent, or run the Master on the SQL host. A node pool or a remote database hostname is not supported. The worker handles media I/O; BackupX sends SQL through Microsoft's Go driver, without passing credentials to a shell or child-process command line.

## Prerequisites

- SQL Server on Linux x64 or Windows x64, with TCP enabled and a known port.
- A SQL authentication login with the **sysadmin** server role (required by VDI).
- A current BackupX Master and Agent built from this source, plus the platform-specific worker on the execution node's `PATH`.
- Enough local temporary disk space for the uncompressed `.bak` and any subsequent compression. Uploads and retention use the existing BackupX pipeline; remote Agent encryption remains unsupported.

TLS is enabled. Certificate validation is enabled by default. For a local instance with a self-signed certificate, explicitly enable **Trust server certificate** in the task. The connection is restricted to `localhost` or a loopback IP.

## Linux worker

Install SQL Server's supported Linux distribution, its `/opt/mssql/lib/libsqlvdi.so`, a C++17 compiler and CMake 3.20 or newer. From the repository root:

```bash
cmake -S native/sqlvdi -B .build-tmp/sqlvdi -DCMAKE_BUILD_TYPE=Release
cmake --build .build-tmp/sqlvdi
sudo cmake --install .build-tmp/sqlvdi --prefix /usr/local
```

CMake downloads the Microsoft SDK headers from a pinned revision and verifies their SHA-256 hashes. `SQLVDI_SDK_DIR` can point to pre-downloaded copies of the same headers for an offline build. The Microsoft shared library is supplied by SQL Server, not redistributed with BackupX.

Run the Agent as `mssql`, with a writable private temporary directory, or configure the shared-memory group permissions described in the [Microsoft VDI specification](https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-backup-vdi-specification). Merely running on the same machine with an unrelated user may fail to open shared memory.

For containers, the usual BackupX Alpine container is **not** a VDI execution environment. Run the Agent and worker alongside SQL Server in its compatible environment; the Master can retain the normal Docker deployment. Separate containers need correctly shared IPC and permissions, not just a shared backup directory. Follow Microsoft's [VDI container requirements](https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-docker-container-configure#enable-vdi-backup-and-restore-in-containers) before using this topology. Container deployment is not automatically configured by BackupX.

## Windows worker and Agent

Use the SQL Server x64 VDI COM component installed and registered by SQL Server, Visual Studio's C++ build tools, the Windows SDK, CMake and Go 1.25+. In PowerShell at the repository root:

```powershell
cmake -S native/sqlvdi -B .build-tmp/sqlvdi-windows -A x64
cmake --build .build-tmp/sqlvdi-windows --config Release
$env:CGO_ENABLED = '0'
go -C server build -o ../.build-tmp/backupx.exe ./cmd/backupx
```

Place `backupx.exe` and the worker from `.build-tmp/sqlvdi-windows/Release/backupx-sqlvdi.exe` in the chosen installation directory. Add that directory to the Agent process's `PATH`. Use an OS account that can access the instance's VDI shared objects and the temporary directory.

The existing node installer targets Linux; Windows installation is manual. Create a node in the console and use its token with the existing Agent configuration:

```powershell
$env:PATH = 'C:\BackupX;' + $env:PATH
$env:BACKUPX_AGENT_MASTER = 'https://backup.example.com'
$env:BACKUPX_AGENT_TOKEN = '<node token>'
$env:BACKUPX_AGENT_TEMP_DIR = 'C:\BackupX\tmp'
C:\BackupX\backupx.exe agent
```

For unattended execution, use your existing Windows process supervisor or Task Scheduler. `backupx agent` is a console application, not a Windows Service executable. A named instance such as `SQLEXPRESS` requires **Windows instance name** in the task and its actual TCP port; the port is not discovered through SQL Browser. Leave the instance name empty for the default instance and for Linux.

## Configure and restore

1. Select **SQL Server (VDI)** and the fixed execution node.
2. Enter the loopback host, TCP port, login/password and one database name.
3. Set the optional Windows instance name and certificate option.
4. Select storage targets and the schedule, then run a manual backup first.

Backup success requires both the VDI worker and the SQL command to succeed. Output is flushed before acknowledging `VDC_Complete`; older servers without this command are flushed before worker success. Failed or cancelled backups are not uploaded, and their local temporary directory is removed. Cancellation closes the worker's control pipe, invokes VDI abort/close, and force-stops an unresponsive worker after five seconds.

The existing restore action downloads and decompresses the `.bak`, then streams it through VDI with `RESTORE DATABASE ... WITH CHECKSUM`. It intentionally does not issue `WITH REPLACE`, force-disconnect database clients or rewrite file locations. SQL Server may reject restore because the database is in use, its files conflict or its overwrite protections apply; resolve those conditions explicitly. Restoring under another name or with `MOVE` currently requires SQL Server's own tools.

Automatic verification drills are unavailable for this task type. A successful transfer or checksum is **not a completed restore drill**. Before relying on backups, restore a disposable database on each target OS and check its data (and `DBCC CHECKDB` where appropriate). Windows cross-compilation and mocked VDI tests do not establish real COM/shared-memory or database compatibility.

## Development checks

The native protocol check links the production worker with a fake VDI library; it does not need SQL Server. After downloading the pinned Linux headers into `.build-tmp/sdk/linux`:

```bash
c++ -std=c++17 -pthread -I .build-tmp/sdk/linux native/sqlvdi/main.cpp \
native/sqlvdi/tests/mock_vdi.cpp -o .build-tmp/sqlvdi-worker-test
TMPDIR="$PWD/.build-tmp" python3 native/sqlvdi/tests/check_worker.py .build-tmp/sqlvdi-worker-test
```

Sources: [Microsoft VDI reference](https://learn.microsoft.com/en-us/sql/relational-databases/backup-restore/vdi-reference/reference-virtual-device-interface), [Linux SDK](https://github.com/microsoft/sql-server-samples/tree/master/samples/features/sqlvdi-linux), [Windows SDK](https://github.com/microsoft/sql-server-samples/tree/master/samples/features/sqlvdi).

### Real SQL Server acceptance test

Run only on a dedicated test instance. This creates a unique `backupx_vdi_it_*` database, seeds it, backs it up, drops that test database, restores it, checks data and runs `DBCC CHECKDB`, then removes the test database. It does not use an existing application database. The real native worker must be on `PATH`.

```bash
export BACKUPX_SQLSERVER_INTEGRATION=1
export BACKUPX_SQLSERVER_TEST_USER=backup_test
# Set BACKUPX_SQLSERVER_TEST_PASSWORD securely in the current process environment.
# Optional: BACKUPX_SQLSERVER_TEST_PORT, BACKUPX_SQLSERVER_TEST_INSTANCE,
# BACKUPX_SQLSERVER_TEST_TRUST_CERTIFICATE=1 for a self-signed local certificate.
TMPDIR="$PWD/.build-tmp" go -C server test ./internal/backup -run '^TestSQLServerVDIRoundTrip$' -v -count=1
```

On Windows, set the same environment variables with PowerShell `$env:NAME` and run the same `go test` command. This test is skipped by default; compilation and mocked tests do not replace running it on each real OS.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
sidebar_position: 1
title: 备份类型
description: 文件、MySQL、PostgreSQL、SQLite 和 SAP HANA — 各自的能力与配置说明。
description: 文件、MySQL、PostgreSQL、SQLite、SQL Server 和 SAP HANA — 各自的能力与配置说明。
---

# 备份类型

BackupX 支持五种内置备份类型,类型决定了用哪个 runner 执行。
BackupX 支持以下内置备份类型,类型决定了用哪个 runner 执行。

当任务路由到远程 Agent 时,源路径和外部工具都会在该 Agent 主机上解析。多存储目标上传仍会逐目标记录结果;只要至少一个目标上传成功,备份记录即为成功,详情中的目标结果表会展示部分失败。

Expand Down Expand Up @@ -52,3 +52,7 @@ CDC 仓库会在不同文件、不同快照之间复用相同内容。完整恢
## 删除行为

删除备份任务时,BackupX 会从所有存储目标上移除备份产物,但保留备份记录以供审计。删除任务同时拆除其 Cron 定时调度。

## SQL Server (VDI)

[SQL Server VDI](./sql-server) 需要在数据库主机安装原生组件,支持 Linux 和 Windows 的 COPY_ONLY 完整备份。
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
sidebar_position: 4
title: SQL Server VDI
description: 在 Linux 和 Windows SQL Server 主机通过 VDI 执行原生完整备份。
---

# SQL Server VDI

SQL Server 类型生成原生 `.bak`,执行 `BACKUP DATABASE ... WITH COPY_ONLY, CHECKSUM`。COPY_ONLY 不改变现有差异备份基线。每个任务只处理一个数据库;本次不支持 `tempdb`、差异备份和事务日志备份。

Master 可以部署在其他机器。**执行节点和 `backupx-sqlvdi` 必须位于 SQL Server 所在主机,并能访问同一共享内存环境**。任务必须选择该固定 Agent,或者在 SQL Server 主机运行 Master;不支持节点池和远程数据库地址。原生组件仅处理 VDI 介质,Go 进程使用微软驱动发送 SQL,数据库密码不会传入 shell 或子进程参数。

## 前置条件

- Linux x64 或 Windows x64 SQL Server,启用 TCP 并确认实际端口。
- SQL 登录账号具有 **sysadmin** 服务器角色,这是 VDI 要求。
- Master、Agent 均使用包含此功能的版本;对应平台的原生组件位于执行节点进程的 `PATH`。
- 临时目录有足够空间容纳未压缩 `.bak` 及后续压缩产物。上传、保留策略沿用现有链路,远程 Agent 仍不支持 BackupX 加密。

默认启用 TLS 并校验服务器证书。若本机 SQL Server 使用自签名证书,需显式打开任务中的“信任服务器证书”。主机只允许 `localhost` 或回环 IP。

## Linux 部署

准备 SQL Server 支持的 Linux 发行版、SQL Server 自带的 `/opt/mssql/lib/libsqlvdi.so`、C++17 编译器和 CMake 3.20+。在项目根目录执行:

```bash
cmake -S native/sqlvdi -B .build-tmp/sqlvdi -DCMAKE_BUILD_TYPE=Release
cmake --build .build-tmp/sqlvdi
sudo cmake --install .build-tmp/sqlvdi --prefix /usr/local
```

构建时从固定微软仓库版本下载 SDK 头文件,并验证 SHA-256;离线构建可以用 `SQLVDI_SDK_DIR` 指向相同版本的头文件。微软动态库由 SQL Server 安装提供,不随 BackupX 分发。

推荐 Agent 使用 `mssql` 身份运行,并使用该账号可写的独立临时目录;也可以按[微软规范](https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-backup-vdi-specification)设置双向用户组权限。仅在同机运行但权限不匹配,仍会导致 VDI 失败。

默认 BackupX Alpine 镜像不是 VDI 执行环境。Master 可继续使用原有 Docker 部署,Agent 和原生组件应运行于 SQL Server 的兼容环境中。跨容器需要共享 IPC 和正确权限,仅共享备份目录不够;请先核对[微软容器 VDI 要求](https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-docker-container-configure#enable-vdi-backup-and-restore-in-containers)。BackupX 不会自动修改容器或 SQL Server 配置。

## Windows 部署

需要 SQL Server 安装并注册的 x64 VDI COM 组件、Visual Studio C++ 构建工具、Windows SDK、CMake 和 Go 1.25+。在项目根目录的 PowerShell 中执行:

```powershell
cmake -S native/sqlvdi -B .build-tmp/sqlvdi-windows -A x64
cmake --build .build-tmp/sqlvdi-windows --config Release
$env:CGO_ENABLED = '0'
go -C server build -o ../.build-tmp/backupx.exe ./cmd/backupx
```

将 `backupx.exe` 和 `.build-tmp/sqlvdi-windows/Release/backupx-sqlvdi.exe` 放入安装目录,并将目录加入 Agent 进程的 `PATH`。运行身份必须能访问实例的 VDI 共享对象和临时目录。

当前一键节点安装器面向 Linux;Windows 使用手动部署。在控制台创建节点,使用其令牌启动:

```powershell
$env:PATH = 'C:\BackupX;' + $env:PATH
$env:BACKUPX_AGENT_MASTER = 'https://backup.example.com'
$env:BACKUPX_AGENT_TOKEN = '<节点令牌>'
$env:BACKUPX_AGENT_TEMP_DIR = 'C:\BackupX\tmp'
C:\BackupX\backupx.exe agent
```

长期运行可交给已有进程托管器或 Windows 任务计划程序。`backupx agent` 是控制台程序,不能直接作为 Windows Service 注册。对于 `SQLEXPRESS` 等命名实例,任务填写“Windows 实例名称”和该实例实际 TCP 端口;不通过 SQL Browser 自动发现端口。默认实例和 Linux 留空实例名称。

## 配置、恢复与验证

1. 选择“SQL Server (VDI)”和数据库所在固定节点。
2. 填写回环地址、TCP 端口、账号密码、一个数据库名称。
3. 按需填写 Windows 实例名和证书选项。
4. 配置存储和计划,先手动执行一次备份。

只有原生组件和 SQL 命令都成功,才会上报备份成功。支持 `VDC_Complete` 时在回应前完成落盘;旧版本在原生组件退出成功前完成落盘。失败或取消不会上传半成品,并清理任务临时目录。取消通过控制管道 EOF 触发 VDI 中止和关闭;原生库无响应时五秒后强制退出。

现有恢复入口下载、解压备份后,通过 VDI 执行 `RESTORE DATABASE ... WITH CHECKSUM`。不会自动使用 `WITH REPLACE`、强制踢掉数据库连接或更改数据库文件位置。数据库被占用、文件冲突或触发 SQL Server 覆盖保护时会失败,需要管理员明确处理。恢复到另一个数据库名或使用 `MOVE` 目前请使用 SQL Server 工具。

此类型暂不支持自动验证演练。传输成功、校验和通过不等于恢复验收完成;上线前应在每种目标系统上备份并恢复一个可丢弃数据库,核对数据,必要时执行 `DBCC CHECKDB`。Windows 交叉编译及模拟 VDI 测试不代表真实 COM、共享内存和数据库已通过兼容性验证。

## 开发验证

原生协议检查将真实组件源码与模拟 VDI 库链接,不需要 SQL Server。准备固定版本的 Linux SDK 头文件到 `.build-tmp/sdk/linux` 后执行:

```bash
c++ -std=c++17 -pthread -I .build-tmp/sdk/linux native/sqlvdi/main.cpp \
native/sqlvdi/tests/mock_vdi.cpp -o .build-tmp/sqlvdi-worker-test
TMPDIR="$PWD/.build-tmp" python3 native/sqlvdi/tests/check_worker.py .build-tmp/sqlvdi-worker-test
```

参考:[微软 VDI 规范](https://learn.microsoft.com/en-us/sql/relational-databases/backup-restore/vdi-reference/reference-virtual-device-interface)、[Linux SDK](https://github.com/microsoft/sql-server-samples/tree/master/samples/features/sqlvdi-linux)、[Windows SDK](https://github.com/microsoft/sql-server-samples/tree/master/samples/features/sqlvdi)。

### 真实 SQL Server 验收

仅在专用测试实例运行。此测试创建唯一的 `backupx_vdi_it_*` 数据库,写入数据、备份、删除该测试库、恢复、核对数据并执行 `DBCC CHECKDB`,最后删除测试库;不会使用已有业务库。原生组件必须位于 `PATH`。

```bash
export BACKUPX_SQLSERVER_INTEGRATION=1
export BACKUPX_SQLSERVER_TEST_USER=backup_test
# Set BACKUPX_SQLSERVER_TEST_PASSWORD securely in the current process environment.
# Optional: BACKUPX_SQLSERVER_TEST_PORT, BACKUPX_SQLSERVER_TEST_INSTANCE,
# BACKUPX_SQLSERVER_TEST_TRUST_CERTIFICATE=1 for a self-signed local certificate.
TMPDIR="$PWD/.build-tmp" go -C server test ./internal/backup -run '^TestSQLServerVDIRoundTrip$' -v -count=1
```

Windows 请在 PowerShell 用 `$env:变量名` 设置相同环境变量,再运行同一个 `go test` 命令。默认未启用此测试;编译和模拟测试通过不能代替两种真实系统上的验收。
1 change: 1 addition & 0 deletions docs-site/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const sidebars: SidebarsConfig = {
'features/backup-types',
'features/storage-backends',
'features/sap-hana',
'features/sql-server',
'features/multi-node',
'features/notifications',
],
Expand Down
Loading
Loading