> For the complete documentation index, see [llms.txt](https://docs.postgresql.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.postgresql.tw/appendixes/contrib/basebackup-to-shell.md).

# F.4. basebackup\_to\_shell — 「shell」pg\_basebackup 模組範例 \#

[F.4.1. 設定參數](#BASEBACKUP-TO-SHELL-CONFIGURATION-PARAMETERS)

[F.4.2. 作者](#BASEBACKUP-TO-SHELL-AUTHOR)

`basebackup_to_shell` 新增名為 `shell` 的自訂基礎備份目標。這讓你可以執行 `pg_basebackup --target=shell`，或依此模組的設定執行 `pg_basebackup --target=shell:DETAIL_STRING`，使伺服器管理者選擇的伺服器命令針對備份程序產生的每個 tar 封存檔執行。該命令會透過標準輸入接收封存檔內容。

此模組主要是示範如何透過擴充功能模組建立新的備份目標，但在某些情況下本身也可能有用。此模組必須透過 [shared\_preload\_libraries](/server-administration/runtime-config/runtime-config-client.md#GUC-SHARED-PRELOAD-LIBRARIES) 或 [local\_preload\_libraries](/server-administration/runtime-config/runtime-config-client.md#GUC-LOCAL-PRELOAD-LIBRARIES) 載入，才能運作。

## F.4.1. 設定參數 [#](#BASEBACKUP-TO-SHELL-CONFIGURATION-PARAMETERS)

`basebackup_to_shell.command` (`string`): 伺服器應針對備份程序產生的每個封存檔執行的命令。若命令字串中出現 `%f`，會以封存檔名稱（例如 `base.tar`）取代。若命令字串中出現 `%d`，會以使用者提供的目標詳細資料取代。命令字串使用 `%d` 時必須提供目標詳細資料，否則禁止提供。基於安全性原因，目標詳細資料只能包含英數字元。若命令字串中出現 `%%`，會以單一 `%` 取代。若命令字串中的 `%` 後接其他任何字元，或位於字串末尾，便會發生錯誤。

`basebackup_to_shell.required_role` (`string`): 使用 `shell` 備份目標所需的角色。若未設定，任何複寫使用者都可使用 `shell` 備份目標。

## F.4.2. 作者 [#](#BASEBACKUP-TO-SHELL-AUTHOR)

Robert Haas `<rhaas@postgresql.org>`

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/basebackup-to-shell.html)（原文版本：18.6；核對日期：2026-09-06）


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.postgresql.tw/appendixes/contrib/basebackup-to-shell.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
