copytable with the /go/copytable Command

/go/copytable pushes one table from a database on this server to a remote server. It: The copy goes one way, from the server you run the command on to the remote server. Only the named table is copied, with its structure and data. Other tables, views, and database users are not. Every admin action in GoAdmio has a matching /go/ command, so anything you can click you can also script.

Quick start

# Copy the table shop_db.orders to a remote server, keeping the same database name
/go/copytable shop_db orders 203.0.113.10 'RemoteRootPassword'

Arguments

# Argument Required Default Notes
1 database Yes — The local database that holds the table.
2 table Yes — The table to copy. The table keeps its name on the remote server.
3 remote-server Yes — IP address or hostname of the remote server.
4 remote-password Yes — The remote server’s root SSH password. See Security.
5 target-database No Same as database Database to import into on the remote server. It is created if it doesn’t exist.
6 ssh-port No 22 SSH port of the remote server.

Use plain names (letters, numbers, and underscores) for the database, table, and target database. They are inserted into shell and SQL commands without quoting.

Examples

# Same database name on the remote server
/go/copytable shop_db orders 203.0.113.10 'RemoteRootPassword'

# Import into a different database on the remote server
/go/copytable shop_db orders 203.0.113.10 'RemoteRootPassword' shop_copy

# Custom SSH port, same database name (note the empty fifth argument)
/go/copytable shop_db orders 203.0.113.10 'RemoteRootPassword' "" 2222

# Different database name and custom SSH port
/go/copytable shop_db orders 203.0.113.10 'RemoteRootPassword' shop_copy 2222

# Verify the result on the remote server
ssh -p 22 root@203.0.113.10 "mariadb -e 'SELECT COUNT(*) FROM shop_copy.orders;'"

# Delete the dump files afterwards (run on both servers)
rm -f /root/shop_db-orders.sql

Output

The command prints a single progress line that updates in place:

Copying shop_db.orders Database Table to 203.0.113.10 | Importing...

When you use a target database, the last step reads Importing to <target-database>....

The stages shown are Dumping..., Copying..., and Importing.... A start line is also printed first and includes your arguments with the password hidden:

[Nov 19 12:00:00]# copytable shop_db orders 203.0.113.10 ********

Outcome What you get
Copy attempted The progress line, then exit status 0.
Another instance holds the lock Instance (<name>) already running. and exit status 1.
Table doesn’t exist locally Table <database>.<table> doesn't exist. and exit status 1.

[!WARNING]
The command does not check whether the dump, upload, or import worked, and SSH errors are hidden. Exit status 0 and a finished progress line do not prove the table arrived. Check the table on the remote server (see Examples).

Security

[!WARNING]
The remote password is passed as a command-line argument and used with sshpass -p, so it can be visible in the process list and saved in your shell history. The start line and the log hide it, but nothing else does. SSH host key checking is also turned off, so the remote server’s identity is not verified.

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