GoAdmio

copywww

Copy a domain's www folder to another domain on this server or to a remote server

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


Overview

/go/copywww copies the website files in /home/<from>/www/ into /home/<to>/www/. The destination can be another domain on this server, or a domain on a remote server reached over SSH. After the copy, it sets the destination files' owner to the destination account.

Use it to clone a site, set up a staging copy, or move a site's files to a new server. Only files are copied. Databases, mail, DNS, and SSL certificates are not.


Quick start

# Copy example.com's website files to staging.example.com on this server
/go/copywww example.com staging.example.com

[!WARNING] Files with the same name in the destination are overwritten, and the copy never deletes anything. For a local copy, the command refuses to run if the destination already has an index.php, index.html, or index.htm, unless you add --force. That safety check doesn't exist for copies to a remote server.


Syntax

# Copy to another domain on this server
/go/copywww <from domain> <to domain> [--force]

# Copy to a domain on a remote server
/go/copywww <from domain> <to domain> <remote server> <remote root password>
Form Behavior
/go/copywww <from> <to> Copies locally. Stops if /home/<to>/www already has an index file.
/go/copywww <from> <to> --force Copies locally, even if the destination has an index file.
/go/copywww <from> <to> <remote server> <remote root password> Copies to /home/<to>/www/ on the remote server.

The form is chosen by the number of arguments: two or three for a local copy, exactly four for a remote copy. Any other number prints Invalid Parameters.

Run it as root.


Arguments

Position Argument Required Notes
1 <from domain> Yes The source. /home/<from>/www/ must exist on this server.
2 <to domain> Yes The destination. The account must already exist, locally or on the remote server.
3 --force No Local copies only. Skips the check for an existing index file.
3 <remote server> Remote copies An IP address or hostname that contains a dot.
4 <remote root password> Remote copies The root SSH password of the remote server. Use single quotes if it contains special characters.

A custom SSH port can't be used. The script reads a fifth argument as a port, but a fifth argument makes the command print Invalid Parameters, so remote copies always use port 22.


Output

Situation What you see
Local copy Transferring files from <from> to <to>... is printed after the copy has finished.
Remote copy Transferring files from <from> to <to>... is printed before the copy starts.
Destination already has an index file Unable to copy files, The directory /home/<to>/www is not empty. The command exits with status 1.
Remote server name has no dot Invalid Remote Server <server> and exit status 1.
Wrong number of arguments Invalid Parameters

The copy itself prints nothing, apart from errors. The status line is printed even if the copy failed, so don't treat it as a sign of success.

Every run is logged with a timestamp, for example [Nov 20 09:15:02]# copywww example.com staging.example.com 203.0.113.20 ********. The log shows the first three arguments and then asterisks, so the remote password is not saved in it.


Examples

# Create a staging copy on the same server
/go/copywww example.com staging.example.com
# Overwrite a destination that already has an index file
/go/copywww example.com staging.example.com --force
# Copy to the same domain on a remote server
/go/copywww example.com example.com 203.0.113.20 'RemoteRootPassword'
# Copy to a different domain name on a remote server, without saving the password in your shell history
read -rs RemotePass
/go/copywww example.com newexample.com 203.0.113.20 "$RemotePass"
# Compare folder sizes after copying
du -sh /home/example.com/www /home/staging.example.com/www

Troubleshooting

Symptom Likely cause Fix
Unable to copy files, The directory ... is not empty. The destination has an index.php, index.html, or index.htm. Only these three files are checked. Use --force if you want to overwrite, or remove the files.
Invalid Remote Server The server name has no dot, such as localhost or an IPv6 address. Use an IPv4 address or a full hostname.
Invalid Parameters The argument count doesn't match a form, for example when a port is added. Use one of the forms in Syntax.
chown: invalid user The account's username isn't the same as its domain, or the account doesn't exist. Run /go/fix <to> to correct ownership.
rsync: mkdir ... failed: No such file or directory The destination account doesn't exist. Create it first with create.
sshpass: command not found sshpass isn't installed on this server. Install it, then run again.
Permission denied or rsync error ... (code 255) Wrong password, root password login is disabled on the remote server, or the remote server doesn't use port 22. Check the password and the SSH settings on the remote server (see permitrootlogin).
sudo: command not found from the remote server The remote copy runs sudo rsync there. Install sudo on the remote server.
The copied site shows errors or points to the old domain or database Configuration files such as wp-config.php are copied unchanged. Update the database settings and site URL for the new domain.
Files deleted from the source still exist in the destination The copy never deletes files. Remove them from the destination by hand.
The copy was interrupted or is slow A large site, or the connection dropped. Run the command again. It copies only what is missing or changed.

Details

Steps

Local copy

  1. Unless --force is given, checks /home/<to>/www for index.php, index.html, or index.htm, and stops if one exists.
  2. Copies /home/<from>/www/ to /home/<to>/www/ with rsync.
  3. Sets the owner and group of /home/<to>/www to <to> with chown -R <to>:<to>.
  4. Prints the status line.

Remote copy

  1. Checks that the remote server name contains a dot.
  2. Prints the status line.
  3. Copies /home/<from>/www/ to root@<remote server>:/home/<to>/www/ with rsync over SSH.
  4. Connects to the remote server and runs chown -R <to>:<to> /home/<to>/www.

The ownership step uses the domain name as the username. This works when the account's username is the same as its domain, which is the default (see create).

How the copy behaves

rsync option Effect
-a Archive mode: keeps permissions, timestamps, and folder structure.
-z Compresses data during the transfer.
-l Copies symbolic links as links.
-h Human-readable numbers. Nothing is printed unless an error occurs.

Existing files in the destination that differ from the source are overwritten, and files that exist only in the destination are kept. Hidden files such as .htaccess are copied too.

Remote copies use sshpass, which puts the password on the command line, so it can be seen in the process list while the command runs. The SSH connection doesn't check or save the remote server's host key.


See also

Command Description
copy Copy a GoAdmio site from one server to another
copymail Copy a domain's mailboxes to the same domain on another GoAdmio server
copydb Copy a MySQL/MariaDB database from one server to another
fix Fix GoAdmio file and folder permissions
create Create a GoAdmio account from the command line
permitrootlogin Allow root SSH login from a specific IP