/go/mysqlsync: mysqlsync from the Command Line

/go/mysqlsync copies every MariaDB database, user, and grant from this server to another GoAdmio server. It does not export and import SQL. It stops MariaDB and copies the whole data directory, /var/lib/mysql, with rsync. Run it on the source server. It: Every admin action in GoAdmio has a matching /go/ command, so anything you can click you can also script.

Quick start

# Copy MariaDB to a new server, using its root password
/go/mysqlsync 203.0.113.20 'RemoteRootPass'

Arguments

Position Name Required Default Notes
1 <remote-server> Yes — Hostname or IP address of the target server.
2 <remote-password> Yes — The SSH password of the target server’s root user.
3 [ssh-port] No 22 SSH port of the target server.

The target must allow root login over SSH with a password (see permitrootlogin). The command does not check its arguments.

Examples

# Default SSH port
/go/mysqlsync 203.0.113.20 'RemoteRootPass'

# Custom SSH port
/go/mysqlsync 203.0.113.20 'RemoteRootPass' 2222

# Afterwards, on the remote server, check the databases
mariadb -e "SHOW DATABASES;"

# If the copy was interrupted, bring MariaDB back on this server
systemctl start mariadb

Output

The command prints one line, then the rsync progress. SSH messages are hidden, so connection and login errors do not appear.

Copying MariaDB/MySQL to 203.0.113.20...

When it finishes it writes 1 to /usr/local/goadmio/tmp/serversync/MariaDB, a flag file that records that the MariaDB copy ran. It is written even if a step failed. Every call is also appended to /var/log/go/mysqlsync.log. The exit code is 0 in nearly every case, so do not use it to detect failures.

Security

[!WARNING]
The command log records the remote root password in plain text, because it saves all arguments. The password is also visible in the process list while the command runs, and this server’s MariaDB root password is visible in the process list of the remote server for a moment. SSH host keys are not checked (StrictHostKeyChecking=no), so run it only between servers on a trusted network.

See the full reference at /go/mysqlsync 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 *