Command line interface
The pgmoneta-cli command line interface controls your interaction with pgmoneta.
It is important that you only use the pgmoneta-cli command line interface to operate on your backup directory
Using other commands on the backup directory could cause problems.
pgmoneta-cli 0.20.0
Command line utility for pgmoneta
Usage:
pgmoneta-cli [ -c CONFIG_FILE ] [ COMMAND ]
Options:
-c, --config CONFIG_FILE Set the path to the pgmoneta_cli.conf file
-h, --host HOST Set the host name
-p, --port PORT Set the port number
-U, --user USERNAME Set the user name
-P, --password PASSWORD Set the password
-L, --logfile FILE Set the log file
-v, --verbose Output text string of result
-V, --version Display version information
-F, --format text|json|raw Set the output format
-C, --compress none|gz|zstd|lz4|bz2 Compress the wire protocol
-E, --encrypt none|aes|aes256|aes192|aes128 Encrypt the wire protocol
-s, --sort asc|desc Sort result (for list-backup)
--cascade Cascade a retain/expunge backup
-?, --help Display help
Commands:
annotate Annotate a backup with comments
archive Archive a backup from a server
backup Backup a server
clear <what> Clear data, with:
- 'prometheus' to reset the Prometheus statistics
compress Compress a file using configured method
conf <action> Manage the configuration, with one of subcommands:
- 'get' to obtain information about a runtime configuration value
conf get <parameter_name>
- 'ls' to print the configurations used
- 'reload' to reload the configuration
- 'set' to modify a configuration value;
conf set <parameter_name> <parameter_value>;
decompress Decompress a file using configured method
decrypt Decrypt a file using master-key
delete Delete a backup from a server
encrypt Encrypt a file using master-key
expunge Expunge a backup from a server
info Information about a backup
list-backup List the backups for a server
mode Switch the mode for a server
ping Check if pgmoneta is alive
restore Restore a backup from a server
retain Retain a backup from a server
shutdown Shutdown pgmoneta
status [details] Status of pgmoneta, with optional details
verify Verify a backup from a server
pgmoneta: https://pgmoneta.github.io/
Report bugs: https://github.com/pgmoneta/pgmoneta/issuesbackup
Backup a server
The command for a full backup is
pgmoneta-cli backup <server>Example
pgmoneta-cli backup primaryThe command for an incremental backup is
pgmoneta-cli backup <server> <identifier>where the identifier is the identifier for a backup.
Example
pgmoneta-cli backup primary 20250101120000list-backup
List the backups for a server
Command
pgmoneta-cli list-backup <server> [--sort asc|desc]The --sort option allows sorting backups by timestamp:
ascfor ascending order (oldest first)descfor descending order (newest first)
Example
pgmoneta-cli list-backup primaryExample with sorting
pgmoneta-cli list-backup primary --sort descrestore
Restore a backup from a server
Command
pgmoneta-cli restore <server> [<timestamp>|oldest|newest] [[current|name=X|xid=X|lsn=X|time=X|inclusive=X|timeline=X|action=X|primary|replica],*] <directory>where
currentmeans copy the Write-Ahead Log (WAL ), and restore to first stable checkpointname=Xmeans copy the Write-Ahead Log (WAL ), and restore to the label specifiedxid=Xmeans copy the Write-Ahead Log (WAL ), and restore to the XID specifiedtime=Xmeans copy the Write-Ahead Log (WAL ), and restore to the timestamp specifiedlsn=Xmeans copy the Write-Ahead Log (WAL ), and restore to the Log Sequence Number (LSN) specifiedinclusive=Xmeans that the restore is inclusive of the specified informationtimeline=Xmeans that the restore is done to the specified information timelineaction=Xmeans which action should be executed after the restore (pause, shutdown)
Example
pgmoneta-cli restore primary newest name=MyLabel,primary /tmpverify
Verify a backup from a server
Command
pgmoneta-cli verify <server> <directory> [failed|all]Example
pgmoneta-cli verify primary oldest /tmparchive
Archive a backup from a server
Command
pgmoneta-cli archive <server> [<timestamp>|oldest|newest] [[current|name=X|xid=X|lsn=X|time=X|inclusive=X|timeline=X|action=X|primary|replica],*] <directory>Example
pgmoneta-cli archive primary newest current /tmpdelete
Delete a backup from a server
Command
pgmoneta-cli delete <server> [<timestamp>|oldest|newest]Example
pgmoneta-cli delete primary oldestretain
Retain a backup from a server. The backup will not be deleted by the retention policy
Command
pgmoneta-cli retain [--cascade] <server> [<timestamp>|oldest|newest]Example
pgmoneta-cli retain primary oldestexpunge
Expunge a backup from a server. The backup will be deleted by the retention policy
Command
pgmoneta-cli expunge [--cascade] <server> [<timestamp>|oldest|newest]Example
pgmoneta-cli expunge primary oldestencrypt
Encrypt the file in place, remove unencrypted file after successful encryption.
Command
pgmoneta-cli encrypt <file>decrypt
Decrypt the file in place, remove encrypted file after successful decryption.
Command
pgmoneta-cli decrypt <file>compress
Compress the file in place, remove uncompressed file after successful compression.
Command
pgmoneta-cli compress <file>decompress
Decompress the file in place, remove compressed file after successful decompression.
Command
pgmoneta-cli decompress <file>info
Information about a backup.
Command
pgmoneta-cli info <server> <timestamp|oldest|newest>ping
Verify if [pgmoneta][pgmoneta] is alive
Command
pgmoneta-cli pingExample
pgmoneta-cli pingmode
[pgmoneta][pgmoneta] detects when a server is down. You can bring a server online or offline using the mode command.
Command
pgmoneta-cli mode <server> <online|offline>Example
pgmoneta-cli mode primary offlineor
pgmoneta-cli mode primary online[pgmoneta][pgmoneta] will keep basic services running for an offline server such that you can verify a backup or do a restore.
shutdown
Shutdown [pgmoneta][pgmoneta]
Command
pgmoneta-cli shutdownExample
pgmoneta-cli shutdownstatus
Status of [pgmoneta][pgmoneta], with a details option
Command
pgmoneta-cli status [details]Example
pgmoneta-cli status detailsconf
Manage the configuration
Command
pgmoneta-cli conf [reload | ls | get | set]Subcommand
reload: Reload configurationls: To print the configurations usedget <config_key>: To obtain information about a runtime configuration valueset <config_key> <config_value>: To modify the runtime configuration value
Example
pgmoneta-cli conf reload
pgmoneta-cli conf ls
pgmoneta-cli conf get server.primary.host
pgmoneta-cli conf set encryption aes-256-cbcconf get
Get the value of a runtime configuration key, or the entire configuration.
- If you provide a
<config_key>, you get the value for that key.- For main section keys, you can use either just the key (e.g.,
host) or with the section (e.g.,pgmoneta.host). - For server section keys, use the server name as the section (e.g.,
server.primary.host,server.myserver.port).
- For main section keys, you can use either just the key (e.g.,
- If you run
pgmoneta-cli conf getwithout any key, the complete configuration will be output.
Examples
pgmoneta-cli conf get
pgmoneta-cli conf get host
pgmoneta-cli conf get pgmoneta.host
pgmoneta-cli conf get server.primary.host
pgmoneta-cli conf get server.myserver.port` conf set
Set the value of a runtime configuration parameter.
Syntax:
pgmoneta-cli conf set <config_key> <config_value>Examples
# Logging and monitoring
pgmoneta-cli conf set log_level debug5
pgmoneta-cli conf set metrics 5001
pgmoneta-cli conf set management 5002
# Performance tuning
pgmoneta-cli conf set workers 4
pgmoneta-cli conf set backup_max_rate 1000000
pgmoneta-cli conf set compression zstd
# Retention policies
pgmoneta-cli conf set retention "14,2,6,1"Key Formats:
- Main section parameters:
keyorpgmoneta.key- Examples:
log_level,pgmoneta.metrics
- Examples:
- Server section parameters:
server.server_name.keyonly- Examples:
server.primary.port,server.primary.host
- Examples:
Important Notes:
- Setting
metrics=0ormanagement=0disables those services - Invalid port numbers may show success but cause service failures (check server logs)
- Server configuration uses format
server.name.parameter(notname.parameter)
Response Types:
- Success (Applied): Configuration change applied to running instance immediately
- Success (Restart Required): Configuration change validated but requires manual update of configuration files AND restart
- Error: Invalid key format, validation failure, or other errors
Important: Restart Required Changes When a configuration change requires restart, the change is only validated and stored temporarily in memory. To make the change permanent:
- Manually edit the configuration file (e.g.,
/etc/pgmoneta/pgmoneta.conf) - Restart pgmoneta using
systemctl restart pgmonetaor equivalent
Warning: Simply restarting pgmoneta without updating the configuration files will revert the change back to the file-based configuration.
Example of Restart Required Process:
# 1. Attempt to change host (requires restart)
pgmoneta-cli conf set host 192.168.1.100
# Output: Configuration change requires manual restart
# Current value: localhost (unchanged in running instance)
# Requested value: 192.168.1.100 (cannot be applied to live instance)
# 2. Manually edit /etc/pgmoneta/pgmoneta.conf
sudo nano /etc/pgmoneta/pgmoneta.conf
# Change: host = localhost
# To: host = 192.168.1.100
# 3. Restart pgmoneta
sudo systemctl restart pgmoneta
# 4. Verify the change
pgmoneta-cli conf get host
# Output: 192.168.1.100Why Manual File Editing is Required:
pgmoneta-cli conf setonly validates and temporarily stores restart-required changes- Configuration files are not automatically updated by the command
- On restart, pgmoneta always reads from the configuration files on disk
- Without file updates, restart will revert to the original file-based values
clear
Clear data/statistics
Command
pgmoneta-cli clear [prometheus]Subcommand
prometheus: Reset the Prometheus statistics
Example
pgmoneta-cli clear prometheusShell completions
There is a minimal shell completion support for pgmoneta-cli.
Please refer to the manual for detailed information about how to enable and use shell completions.