postgresync with the /go/postgresync Command

/go/postgresync copies all of this server's PostgreSQL data, meaning every database, user, and setting, to another server. It is meant for moving PostgreSQL to a new server. It works on the files of the database, not on the SQL inside. It: Every admin action in GoAdmio has a matching /go/ command, so anything you can click you can also script.

Quick start

# Stop PostgreSQL here so the files don't change during the copy
systemctl stop postgresql

# Copy it to the remote server
/go/postgresync 203.0.113.5 'RemoteRootPassword'

# Start PostgreSQL here again
systemctl start postgresql

Options

Argument Required Default Notes
<remote-server> Yes — The IP address or host name of the remote server.
<remote-password> Yes — The remote server’s root password.
[port] No 22 The SSH port of the remote server.

Both servers need:

  • PostgreSQL installed, with the same major version (see postgresql)
  • the data directory at /var/lib/pgsql/data/, which is the layout on AlmaLinux, Rocky, CentOS, Red Hat, and Fedora

The remote server must allow root to log in over SSH with a password (see permitrootlogin) and have rsync. This server needs sshpass and rsync.

Examples

# Recommended: stop PostgreSQL here while copying
systemctl stop postgresql
/go/postgresync 203.0.113.5 'RemoteRootPassword'
systemctl start postgresql

# The remote SSH server listens on port 2222
/go/postgresync 203.0.113.5 'RemoteRootPassword' 2222

# Check the result on the remote server
ssh root@203.0.113.5 "systemctl status postgresql"

Output

Copying PostgreSQL to 203.0.113.5...
sending incremental file list
base/16384/2619
4.20M 100% 35.20MB/s 0:00:00 (xfr#1, to-chk=210/230)
...

The command prints the progress of rsync. It prints no message when it finishes, and it doesn’t check whether each step worked. The exit status is the one of the last command, which restarts PostgreSQL on the remote server.

Every run is logged to /var/log/go/postgresync.log with a timestamp and the arguments used. The log includes the password you typed.

See the full reference at /go/postgresync and the GoAdmio command index.

GoAdmio is free and open source, with no license fees and no account limits. Read the GoAdmio docs, or see why it is a free cPanel alternative at goadmio.com.

By:

Posted in:


Leave a Reply

Your email address will not be published. Required fields are marked *