Sitecopy 2.0

For quite some time, we have provided a tool for our customers to easily migrate their websites to and from Servebolt environments. With our new Admin Panel and server stack, we’ve also decided to upgrade Sitecopy. The latest version is faster and more user-friendly.

It is a shell command provided with all our Bolts, so some knowledge of using a terminal and SSH is required. And if you ever need help, we are happy to assist you in our Support chat at servebolt.com.

What Sitecopy Does

If you haven’t used Sitecopy before, it might be hard to grasp what it exactly does. But in essence, it’s one shell command to copy one of your websites on host X and move that copy over to host Y.

However, under the hood, it’s just a set of smaller shell commands you can still use if you’re tech-savvy. The main commands used are:

  • ssh To securely connect the two hosts.
  • rsync To efficiently copy files over a network using the aforementioned SSH connection.
  • mysqldump To dump the database creation instructions into a file.
  • mysql To run the instructions from the dump file on the new host.

Don’t be confused by the word mysql in the two latter commands, we still use MariaDB as our (RDBMS) database system.

Moreover, Sitecopy will try to find the correct database credentials based on what CMS you’re using to create a dump of the database. Additionally, it updates the main CMS configuration file on the receiving host with the new credentials. Currently, only WordPress and Magento 2 are supported out of the box. If running another CMS like Laravel, you must explicitly provide Sitecopy with the database credentials.

Lastly, Sitecopy streams the database dump and creation data over the network while running the file transfer in parallel instead of copying and uploading the files linearly, which is slow and takes up more I/O resources.

What Sitecopy Doesn’t Do

  • It does not check if the receiving host has enough disk space. So, before using Sitecopy, remember to double-check how much storage you will need.
  • It does not hide your credentials if you’re writing them out explicitly. So be sure no one is looking over your shoulder that you don’t trust.

How to Use Sitecopy

Simple

The first thing you have to do is to connect to the Servebolt Environment vis SSH. The easiest way to use Sitecopy would be to provide it with the SSH host from which to copy. And lastly, the local database name for the new host:

 $ sitecopy [email protected] newDatabase

Sitecopy should then be smart enough to figure out the rest.

Advanced

As mentioned earlier, if you’re not using WordPress or Magento 2, you might need to enter your credentials manually. Here’s an example of what a very explicit Sitecopy command would look like. But in most cases, you don’t have to be this verbose:

 $ sitecopy \
 # Remote SSH credentials \
 --user=from \
 --host=old.host \
 --port=22 \

 # Remote database credentials \
 --remote-name=oldDatabaseName \
 --remote-user=oldDatabaseUser \
 --remote-host=old.host \
 --remote-pass=oldDatbasePassword \

 # Local database credentials \
 --local-name=newDatabase \
 --local-pass=newDatbasePassword

Source and Destination

When running Sitecopy to migrate websites within the Servebolt cloud, specifying the source and destination directory is unnecessary. But if you’re migrating a website from outside of the Servebolt cloud or want to override where files should be fetched from or placed, you can do so with the --src and --dest parameters:

 $ sitecopy [email protected] newDatabase \
 --src=my/secret/folder \
 --dest=my/new/secret/folder

By default, Sitecopy will use the document root as the source directory. This is either ~/public or ~/site/public, depending on which Servebolt Linux OS you’re on. If you’re migrating from another host, the remote SSH user’s home directory is the source. For the destination directory, the document root is always used.

Exclusion

Lastly, if you ever want to exclude a file or a directory, the parameter --exclude. A single file/directory or a list of files/directories, separated by a comma, can be provided. Globbing is also allowed should you want to exclude similar files/directories. In the example below, we exclude the file image.png, all files ending in .jpg, and the directory don't/want relative to the source directory:

 $ sitecopy [email protected] newDatabase \
 --exclude="image.png,*.jpg,dont/want"

Help

In most cases, a lot of the extra parameters can be dropped, especially --remote-host and --port, as they are usually standard, and/or Sitecopy will usually figure them out. Otherwise, Sitecopy will try to give you a clear error message describing what went wrong. But in most cases, sitecopy USER@HOST DATABASE will go a long way.

If you ever need to see what options are available, you can run Sitecopy with the --help flag:

Old Sitecopy

Sitecopy version 2 is backwards compatible with the older version 1 of Sitecopy, making sure any automated scripts you might have still works. The difference is Sitecopy 2 will simply discard older redundant flags like for example -t wp. If you for some reason still need to use the older version, you can do so with the command sitecopy1.


As always, should you have any additional questions, please don’t hesitate to contact us through our support chat at servebolt.com!