/go/copydb: copydb from the Command Line

/go/copydb clones a database on the same server into a new database that belongs to a hosting account. It: Nothing is sent to another server. To copy a database to a remote server, use copydatabase. To copy a single table to a remote server, use copytable. Every admin action in GoAdmio has a matching /go/ command, so anything you can click you can also script.

Quick start

# Copy shop_db into a new database shop_copy for the account example.com
/go/copydb example.com shop_copy shop_user 'S3cureP4ssw0rd' shop_db

Arguments

# Argument Required Notes
1 domain Yes An existing GoAdmio account. The new database is created under it.
2 new-database Yes Name of the database to create. It must not already be registered in GoAdmio.
3 user Yes Database user for the new database. Not root, go, mysql, horde, or roundcube.
4 password Yes Password for the database user. See Security.
5 source-database Yes The existing database to copy from. It isn’t checked against the account, so any database on the server can be used.

Use plain names (letters, numbers, and underscores). The command does not validate names itself, and the values are inserted into SQL and shell commands without quoting. Avoid spaces and shell special characters in the password for the same reason. For any naming rules on the new database or user, see mysql.

Examples

# Clone a database into a new one for an account
/go/copydb example.com shop_copy shop_user 'S3cureP4ssw0rd' shop_db

# Verify the copy
mariadb -e 'SHOW TABLES FROM shop_copy;'

# Compare row counts for one table in the source and the copy
mariadb -e 'SELECT COUNT(*) FROM shop_db.orders; SELECT COUNT(*) FROM shop_copy.orders;'

Output

Messages and bare percentage numbers, each on its own line. The percentages are meant to drive a progress bar. The output of mysql appears first, then:

Exporting Database shop_db...
99
Importing Database shop_db to shop_copy...
<percentage numbers, one per line>
Database import completed successfully...
100

During the export the dump size isn’t known in advance, so the command prints 99 when the export ends. The import step reports real percentages.

Outcome What you get
Copy attempted The messages above.
No arguments No output, exit status 1.
Validation failure A message from Validation and exit status 1.

[!WARNING]
Database import completed successfully... is printed whether or not the import worked. The command does not check the result of creating the database, the export, or the import. Check the new database yourself (see Examples).

Security

[!WARNING]
The database user’s password is passed as a command-line argument, so it can be visible in the process list and saved in your shell history. The command also passes the MariaDB root password on the command line to mariadb-dump and mariadb, so it is briefly visible in the process list while the copy runs. The log hides the user password but not the root password’s exposure in the process list.

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