GoAdmio Command Line: copymail with /go/copymail

/go/copymail copies a domain's mail folder, /home/<domain>/mail/, from this server to the same path on a remote GoAdmio server, then fixes file permissions on the remote server. It is used when moving a domain's email to a new server. The domain keeps its name. This command does not copy mail from one domain to another on the same server. Every admin action in GoAdmio has a matching /go/ command, so anything you can click you can also script.

Quick start

# Copy example.com's mail to the server at 203.0.113.20
/go/copymail example.com 203.0.113.20 'RemoteRootPassword'

[!WARNING]
The remote root password is saved in plain text in /var/log/go/copymail.log, although the log line ends with asterisks. It is also visible in the process list while the command runs, and the command doesn’t verify the remote server’s SSH host key. Use it only on a network you trust, and remove the password from the log afterwards.

Arguments

Position Argument Required Default Notes
1 <domain> Yes — The domain whose mail is copied. /home/<domain>/mail/ must exist on this server.
2 <remote server> Yes — The IP address or hostname of the destination server.
3 <remote root password> Yes — The root SSH password of the destination server. Put it in single quotes if it contains special characters.
4 <port> No 22 The SSH port of the destination server.

With fewer than three arguments the command prints Invalid Parameters and does nothing.

Examples

# Copy mail to a server that uses the default SSH port
/go/copymail example.com 203.0.113.20 'RemoteRootPassword'

# Copy mail to a server that uses SSH port 2222
/go/copymail example.com 203.0.113.20 'RemoteRootPassword' 2222

# Avoid saving the password in your shell history
read -rs RemotePass
/go/copymail example.com 203.0.113.20 "$RemotePass" 2222

# Compare the size of the mail folder on both servers
du -sh /home/example.com/mail
ssh root@203.0.113.20 "du -sh /home/example.com/mail"

# Run it again just before switching DNS to copy mail that arrived in the meantime
/go/copymail example.com 203.0.113.20 'RemoteRootPassword'

Output

The command prints nothing when it works, because rsync runs without verbose output. Errors from sshpass, rsync, or ssh are shown.

Every run is logged with a timestamp, for example [Nov 20 09:15:02]# copymail example.com 203.0.113.20 ********. The password appears in the log line before the asterisks. See the warning in Quick start.

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