GoAdmio

serversync

Copy a whole GoAdmio server to another server over SSH: accounts, files, databases, SSL certificates, and settings

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


Overview

/go/serversync migrates everything on this server to another GoAdmio server. It connects to the destination as root over SSH, then:

It is a one-time copy of a running server, not a backup. For backups, use snapshot or backup.


Quick start

/go/serversync 203.0.113.10 'RemoteRootPassword'

Syntax

/go/serversync <remote-server> <root-password> [port]
Form Behavior
/go/serversync <remote-server> <root-password> Migrates to the destination using SSH port 22.
/go/serversync <remote-server> <root-password> <port> Same, using a different SSH port.

[!WARNING] The destination should be a fresh server with GoAdmio installed. Files and records that exist on it may be overwritten. Read Before you run first.

Before you run


Arguments

Argument Required Default Notes
<remote-server> Yes — IP address or hostname of the destination.
<root-password> Yes — The destination's root password. Avoid spaces and shell special characters; some of the helper commands receive it without quotes.
[port] No 22 The destination's SSH port.

The command has no --option flags.


Output

Outcome What you get
No arguments Missing Remote Server and exit code 1.
Another run in progress Instance (<name>) already running. and exit code 1.
Connection or login failed REMOTE: Invalid username or password and exit code 1.
Copy started Working... Please be patient, then one . per account as it is created on the destination.
Copy in progress The terminal is cleared every 10 seconds and shows a list of finished tasks (✓ <task>) and a 50-character bar with a percentage.
Finished The output of checkid run on the destination, then a blank line.

The command exits with code 0 after the progress screen ends, even if some of the copying failed.

Logging

Log Content
/var/log/go/serversync.log One line per run: the time, the remote server, ******** in place of the password, and the port.
/var/log/go/serversync/mysql.log Output of mysqlsync.
/var/log/go/serversync/postgre.log Output of postgresync.
/var/log/go/serversync/ssl.log Output of sslsync.
/var/log/go/serversync/<domain>.log Output of homesync for that account.

Locking

The lock file /usr/local/goadmio/lock/serversync.lock blocks a second run. A lock older than one hour is treated as stale and replaced, even if the first run is still going.

Security

[!WARNING] The destination's root password is passed on the command line to many commands, so it is visible in the process list on this server while the sync runs. SSH host keys are not verified, and each account's saved password is sent over SSH in a command line. Use only on a network you trust, and change the destination's root password afterwards.


Examples

# Migrate to a server on the default SSH port
/go/serversync 203.0.113.10 'RemoteRootPassword'
# Migrate to a server with SSH on port 2222
/go/serversync 203.0.113.10 'RemoteRootPassword' 2222
# Watch the logs from another terminal
tail -f /var/log/go/serversync/mysql.log
ls /usr/local/goadmio/tmp/serversync
# On the destination, check that the background tasks have finished
screen -ls

Troubleshooting

Symptom Likely cause Fix
Missing Remote Server No arguments. Pass the server and its root password.
Instance (serversync) already running. A run is active, or one stopped less than an hour ago. Wait, or delete the lock file /usr/local/goadmio/lock/serversync.lock if you are sure no run is active.
REMOTE: Invalid username or password Wrong password or port, root password login disabled, GoAdmio missing on the destination, or any other rsync error. The message matches any error text. Read the real error in /usr/local/goadmio/tmp/scp.db.
The progress screen never reaches 100% A background job didn't finish or didn't record completion, and there is no timeout. Read the logs in /var/log/go/serversync/ and ls /usr/local/goadmio/tmp/serversync. Press Ctrl+C to stop waiting; the background jobs keep running.
Screen errors or odd output when run from a script clear needs a terminal. Run it in an interactive terminal, or set TERM.
Dots appear, but accounts are missing on the destination The output of the remote create call is hidden. Run create for one account on the destination to see the error.
Account owners received welcome emails create emails each account's login details. Warn customers before a migration.
SSL certificates missing on the destination sslsync failed or the DNS check failed. Read ssl.log, then run ssl after the DNS change.
This server is slow during the sync One homesync job per account starts at the same time. Run it in a quiet period.
Tasks still running on the destination after the command ends fix and installmail are started there in the background. Wait until screen -ls on the destination shows no sessions.
Destination firewall or cron is stopped after an aborted run They are stopped at the start and restarted only at the end. Run /go/firewall start and /go/cron restart on the destination.
Duplicate S3 lines in /etc/fstab on the destination The line is appended on every run. Remove the duplicates.
Panel records on the destination didn't change The panel folders may be copied one level too deep. See Notes for maintainers. Check for /var/lib/sqlite/sqlite on the destination.
Hostname on the destination changed /etc/hostname is copied on purpose. Apply or change it with hostname.

Details

What it does

  1. Re-runs itself with sudo if not root, and logs the call with the password hidden.
  2. Stops with Missing Remote Server if no argument was given.
  3. Takes the lock /usr/local/goadmio/lock/serversync.lock.
  4. Clears the progress folder /usr/local/goadmio/tmp/serversync and creates /var/log/go/serversync.
  5. Tests the SSH login by copying a small file to the destination. Any error stops the run with REMOTE: Invalid username or password.
  6. Runs /go/ssh --serversync on both servers to prepare SSH for the transfer. See ssh.
  7. Stops the firewall and cron on the destination with firewall and cron.
  8. Copies /etc/hostname to the destination.
  9. For every folder in /home that has a www folder: writes the account's settings with /go/siteconf, loads them from log/include/site.conf, and runs create on the destination with those settings. Prints a ..
  10. Starts these jobs in the background: mysqlsync, postgresync, sslsync, and one homesync per account.
  11. Shows the progress screen until every job has written its completion marker into /usr/local/goadmio/tmp/serversync.
  12. If this server mounts S3 storage (passwd-s3fs in /etc/fstab), appends that line to the destination's /etc/fstab and copies /etc/passwd-s3fs.
  13. Copies /var/lib/sqlite, /usr/local/goadmio/db, /var/go, and /root/.config/rclone/rclone.conf to the destination.
  14. Starts the firewall and restarts cron on the destination.
  15. Runs checkid on the destination in the foreground, then fix and installmail in the background there.
  16. Removes the lock.
flowchart TD
    A["serversync server password"] --> B["Take lock, test SSH login"]
    B --> C["Prepare SSH, stop firewall and cron on destination"]
    C --> D["Copy hostname"]
    D --> E["create each account on destination"]
    E --> F["Start background jobs: databases, SSL, files per account"]
    F --> G["Progress screen until all jobs finish"]
    G --> H["Copy S3 settings, panel data, rclone config"]
    H --> I["Start firewall and cron on destination"]
    I --> J["checkid, then background fix and installmail"]

What is copied

Item How
Hostname /etc/hostname is copied to the destination.
Accounts (users, limits, web server and PHP-FPM configuration, DKIM, DNS zone, SSL request) create runs on the destination for each account.
Site files and mail homesync, one job per account.
MySQL/MariaDB databases mysqlsync
PostgreSQL data postgresync
SSL certificates sslsync
S3 mount settings The /etc/fstab line and /etc/passwd-s3fs.
Panel databases and system data /var/lib/sqlite, /usr/local/goadmio/db, and /var/go.
rclone configuration /root/.config/rclone/rclone.conf

DNS records are not changed.

After the sync

  1. Wait for the background tasks on the destination to finish (screen -ls).
  2. Check a few accounts, databases, and mailboxes on the destination.
  3. Run the sync again for a last copy if the source changed, then point DNS at the destination.
  4. Change the destination's root password.

Notes for maintainers

Issue Why it matters Suggested fix
The root password is passed with sshpass -p, and as an argument to mysqlsync, postgresync, sslsync, and homesync Visible in the process list. Use SSH keys, or sshpass -e with an environment variable.
StrictHostKeyChecking=no and UserKnownHostsFile=/dev/null Host keys are never verified, so a man-in-the-middle can capture the password. Show the fingerprint once, then pin it.
Account values are placed inside single quotes in the remote create command A quote in a field such as FullName or Description breaks the command or runs code as root on the destination. Escape with printf %q, or send the settings as a file.
site.conf is loaded with source, as root, from each customer's home Anything written in it runs as root. Parse it as data.
Variables are not cleared between accounts A missing field in one account's site.conf keeps the previous account's value, so one customer's settings can reach another. Unset every setting at the start of each loop.
Every homesync job starts at once N parallel transfers can overload the server and the link. Limit concurrency, for example with xargs -P or a semaphore.
The wait loop uses -eq with no timeout A missing or extra completion marker makes it wait forever, and a failed job can't be seen. Use -ge, add a timeout, and report which tasks failed.
The login test reports every error as Invalid username or password Misleading when the real cause is a missing folder or a network error. Print the real message from scp.db.
The lock expires after one hour A long sync can overlap with a second run. Use flock or a PID check.
rsync /var/lib/sqlite root@host:/var/lib/sqlite has no trailing slash on the source rsync copies the folder into the destination, giving /var/lib/sqlite/sqlite, and the same for /usr/local/goadmio/db and /var/go. The panel records may not be replaced. Verify on a test server. Use /var/lib/sqlite/ (trailing slash) on the source.
Errors are hidden (&>/dev/null, >/dev/null 2>&1) and the exit code is 0 Partial failures are invisible. Check every step and exit non-zero on failure.
Firewall and cron are stopped on the destination and restarted only at the end An aborted run leaves the destination unprotected. Restart them in the trap.
The S3 line is appended to /etc/fstab with >> and an unquoted echo Duplicates on every run, and special characters can break the line. Check for the line first, and quote it.
fix and installmail run detached on the destination The command ends before the migration does. Wait for them, or poll screen -ls.
The copy is live, with no final pass Changes made during or after the run are missed. Add a maintenance mode and a final differential sync.

See also

Command Description
create Create a GoAdmio account from the command line
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
copy Copy a GoAdmio site from one server to another
checkid Renumber UIDs/GIDs to match the source server
snapshot Restic-based per-domain snapshot backup and restore
backup Create a backup for all GoAdmio accounts (local and remote)