GoAdmio

copy

Copy one or all GoAdmio accounts (files, mail, SQLite, databases, and settings) to another GoAdmio server over SSH

On this page: Overview · Quick start · Syntax · Options · Output · Examples · Troubleshooting · Details · See also


Overview

/go/copy migrates a hosting account from this server to another GoAdmio server. For each domain it:

The source account is not changed, suspended, or deleted, and DNS is not updated. After the copy, both servers hold the site.

[!WARNING] The remote server's root password is passed on the command line. It is visible in the process list and shell history, and the command writes all its arguments, password included, to /var/log/go/copy.log. See Security.


Quick start

# Copy one account to another GoAdmio server
/go/copy example.com 203.0.113.10 'RemoteRootPassword'

Syntax

# Copy one domain
/go/copy <domain> <remote-server> <remote-root-password> [ssh-port]

# Copy every domain on this server
/go/copy all <remote-server> <remote-root-password> [ssh-port]
Form Behavior
/go/copy <domain> <server> <password> [port] Copies one account.
/go/copy all <server> <password> [port] Runs the single-domain copy for every folder in /home, one after another. Only one all run can be active at a time.
/go/copy (no arguments) Prints Missing Domain and exits.

If you run the command without root privileges, it restarts itself through sudo.

Requirements

Where Requirement
This server sshpass, rsync, sqlite3, and mariadb.
Remote server GoAdmio installed, with a copy that supports --shadow, --grant, and --import. Keep both servers on the same GoAdmio version with update.
Remote server rsync, sudo, and pv (/usr/bin/pv).
Remote server SSH login as root with a password allowed from this server. See permitrootlogin.
Both servers Free disk space in /usr/local/goadmio/tmp for the largest database dump.

Options

copy takes positional arguments, not -- options.

Position Name Required Default Notes
1 Domain, or all Yes — Must exist in the Site table, or the command prints Domain <domain> not exists. and exits.
2 Remote server Yes — IP address or hostname of the destination server.
3 Remote root password Yes — Used with sshpass for every SSH and rsync connection.
4 SSH port No 22

Internal modes

The command calls itself on the remote server with these flags. They are not meant to be run by hand, and each one exits with status 1.

Call What it does
copy <domain> <username> --shadow Replaces the user's line in /etc/shadow with the line saved in /home/<domain>/log/shadow, then deletes that file.
copy <database> <user> <hash> --grant Sets the database user's password hash with GRANT USAGE ... IDENTIFIED BY PASSWORD.
copy <database> --import Imports /usr/local/goadmio/tmp/<database>.sql into the database, with a pv progress bar.

The flags are detected anywhere in the argument list, so avoid passwords or domains that contain --shadow, --grant, or --import.


Output

Progress is printed as the copy runs. rsync shows its own transfer progress, and a . follows each rsync step.

Message Meaning
[<n>/<total>] Copying <domain>... Progress line in all mode.
Copying <domain> to <server>... Start of one account.
Creating Account <domain>... create runs on the remote server. Its JSON result is printed.
Copying WWW Files <domain>... www folder transfer.
Copying MAIL Files <domain>... mail folder transfer.
Copying SQLITE Files <domain>... sqlite folder transfer.
Set Password <domain>... Linux password hash copied.
Set Up Mail <domain>... Mail accounts recreated from the mail folders.
Copying Databases... MySQL/MariaDB databases dumped and imported.
Missing Domain No arguments were given.
Domain <domain> not exists. The domain is not in the Site table.
Instance (copy) already running. An all run started less than an hour ago holds the lock.

Exit status

Situation Exit status
Single domain copied 0, unless the last cleanup command fails.
No arguments, unknown domain, or lock held 1
all mode Always 1, even after a successful run.
Internal modes Always 1.

Security

[!WARNING] Every run appends all its arguments to /var/log/go/copy.log, so the remote root password is stored there in plain text. The password is also visible in ps output and in your shell history. The database root password is passed on the command line to mariadb and mariadb-dump in the same way.

After a migration, remove the line from /var/log/go/copy.log and your shell history, and change the remote server's root password. SSH host key checking is turned off for these connections, so run the command only over a network you trust.


Examples

# One account, default SSH port
/go/copy example.com 203.0.113.10 'RemoteRootPassword'
# One account, SSH on port 2222
/go/copy example.com 203.0.113.10 'RemoteRootPassword' 2222
# Every account on this server
/go/copy all 203.0.113.10 'RemoteRootPassword'
[1/12] Copying example.com...
Copying example.com to 203.0.113.10...
Creating Account example.com...
Copying WWW Files example.com...
.

Troubleshooting

Symptom Likely cause Fix
Missing Domain No arguments were given. Pass a domain or all, the server, and the password.
Domain <domain> not exists. The domain is not in the Site table. Check the spelling. In all mode this also appears for folders in /home that are not hosted domains, and is harmless.
Instance (copy) already running. Another all run holds /usr/local/goadmio/lock/copy.lock. Wait for it to finish. The lock is ignored after one hour.
sshpass: command not found sshpass is not installed here. Install sshpass, then run again.
Permission denied or connection refused Wrong password or port, or root password login is disabled on the remote server. Check the arguments. Enable root login there with permitrootlogin.
create shows an error on the remote server Remote validation failed, for example the domain or username already exists. Fix the reason shown. Copying still continues, so stop the run if the account was not created.
Account creation fails for some accounts A saved setting, such as the description or full name, contains a single quote ('). Remove the quote from the account's details and run again.
Files have the wrong owner on the remote server UIDs and GIDs differ between servers. Run checkid and fix on the remote server.
Remote server's firewall is off after the run The copy was interrupted before the last step. Run /go/firewall start on the remote server.
.sql files left in /usr/local/goadmio/tmp on the remote server The import step does not delete its file. Delete them after checking the databases. They contain the full database contents.
Database content differs from the source The dump was taken while the site was writing data, and tables are not locked. Run again during low traffic, or suspend the account first.
A second all run starts while one is active The lock is deleted when the first domain finishes. Do not start another all run until the first one ends.

Details

What it does

flowchart TD
    A["copy ..."] --> B{"First argument"}
    B -- "none" --> X1["Missing Domain, exit"]
    B -- "all" --> L{"Lock younger than 1 hour?"}
    L -- "Yes" --> X2["Instance already running, exit"]
    L -- "No" --> M["Create lock, run copy for each folder in /home"]
    M --> D
    B -- "a domain" --> D{"Domain in Site table?"}
    D -- "No" --> X3["Domain not exists, exit"]
    D -- "Yes" --> E["Stop remote firewall"]
    E --> F["Create account on remote with create"]
    F --> G["rsync www, mail, sqlite"]
    G --> H["Copy Linux password hash"]
    H --> I["Recreate mail accounts, fix ownership"]
    I --> J["Dump, create, grant, and import each database"]
    J --> K["checkid, start remote firewall, remove lock"]
  1. Appends the call and its arguments to /var/log/go/copy.log.
  2. Looks up the account's username in the Site table in /var/lib/sqlite/site.db. If the domain is missing, it stops.
  3. Stops the firewall on the remote server with firewall.
  4. Regenerates the account's site.conf with siteconf and loads its settings.
  5. Creates the account on the remote server with create, passing every saved setting as an option. As with any create, the account's email address receives the welcome message, and the remote server requests a new SSL certificate.
  6. Copies /home/<domain>/www/ with rsync -azlh.
  7. Copies /home/<domain>/mail/ the same way.
  8. Copies /home/<domain>/sqlite/ the same way.
  9. Copies the account's line from /etc/shadow to the remote server through /home/<domain>/log/shadow, then applies it there with copy --shadow.
  10. Recreates missing email accounts from the copied folders with mail --action create, then sets vmail:vmail ownership on mail.
  11. Sets the account owner on the remote www folder.
  12. For each database registered to the account in /var/lib/sqlite/mysql.db:
    1. Reads the database user's password hash.
    2. Dumps the database with mariadb-dump --skip-lock-tables to /usr/local/goadmio/tmp/<name>.sql.
    3. Copies the dump to the same folder on the remote server.
    4. Creates the database and user there with mysql, using a random temporary password.
    5. Applies the original password hash with copy --grant.
    6. Imports the dump with copy --import.
    7. Deletes the local dump.
  13. Runs checkid on the remote server.
  14. Starts the remote firewall and deletes the lock file.

The command does not check whether a step succeeded before starting the next one. If account creation fails, the file and database copy still runs.

The all lock

In all mode the command writes /usr/local/goadmio/lock/copy.lock and removes it when it exits. A lock younger than one hour blocks a new all run. The single-domain runs started by all also delete the lock file when they finish, so the lock is gone after the first domain.

What is and is not copied

Copied Not copied by this command
Account settings (through create) PostgreSQL databases, see postgresync
www, mail, and sqlite folders SSL certificate files. The remote server requests its own, see sslsync
Linux account password hash Other files in the account's etc and log folders
MySQL/MariaDB databases, with original user passwords Anything not handled by the steps above, such as subdomains, alias domains, FTP accounts, cron jobs, and email filters. Check these on the remote server after the copy.

Files removed from the source after an earlier copy are not removed from the destination, because rsync runs without --delete.


See also

Command Description
create Create a GoAdmio account from the command line
serversync Back up and migrate a GoAdmio server with all configurations
copydb Copy a MySQL/MariaDB database from one server to another
copymail Copy mailboxes from one domain to another
copywww Copy the www directory from one domain to another
mysqlsync Copy MySQL databases from a local to a remote server
postgresync Copy PostgreSQL data to a remote server
sslsync Copy domain account SSL certificates from a local to a remote server
checkid Renumber UIDs/GIDs to match the source server
permitrootlogin Allow root SSH login from a specific IP
firewall Install a firewall on a GoAdmio server
siteconf Write the account's site.conf (used internally)