Sitecopy

Sitecopy is a command-line tool available on all Servebolt environments. It allows you to efficiently migrate websites, sync environments, and precisely move databases or files. You’ll need to be familiar with the terminal and SSH. If you’re new to these concepts, we recommend reviewing our SSH connection guide before starting.

What Sitecopy Does

If you’re new to Sitecopy, it might seem complex at first. Still, its core function is simple: it’s a single command that lets you copy a website from one Servebolt environment to another—whether that’s staging to production, an internal migration, or cloning a project.

Under the hood, Sitecopy automates several powerful shell commands:

  • ssh – Securely connects the two hosts.
  • rsync – Efficiently transfers files over the network.
  • mysqldump – Extracts database structure and content into a portable file.
  • mysql – Imports the database dump into the destination environment.

Database Handling & CMS Support

Sitecopy automatically detects and transfers database credentials for WordPress environments. You must manually provide database credentials if you’re running a different CMS, such as Laravel.

Why Sitecopy is Fast

Unlike traditional methods, Sitecopy streams the database dump and file transfer simultaneously over the network, significantly reducing transfer time and minimising I/O load.

Prerequisites

Before using Sitecopy, ensure you have:

✔️ Sufficient Bolt Storage — Ensure the destination Bolt has enough storage capacity to accommodate the copy of your website, including both files and the database.
✔️ Secure Credentials Handling — If you manually enter database credentials, avoid exposing them in shared or public environments. Consider using environment variables or configuration files to keep credentials secure.
✔️ SSH Access—You must have SSH access to both the source and destination environments. You can achieve this by adding your SSH Key to the Bolt and/or Environment.
✔️ Database Credentials—Sitecopy automatically detects database credentials for WordPress, but you’ll need to provide them manually for other CMS’ (e.g., Laravel).

When to Use Sitecopy

Sitecopy is ideal for fast, efficient migrations and synchronisations between Servebolt environments. Below are the most common use cases where Sitecopy can help:

  • Setting up a new staging environment.
  • Pushing changes from staging to production.
  • Migrating an entire site to another Servebolt environment.

How to Use Sitecopy

Before running Sitecopy, you must connect to your Servebolt environment via SSH.

Run a Basic Sitecopy Command

To copy a site from source to destination, use the following command:

sitecopy from@old.host newDatabase

This command provides Sitecopy with the following information, found in the Admin Panel:

  • from — Represents the SSH user from which the site is being copied.
  • old.host — The hostname where the current website is hosted.
  • newDatabase — The name of the destination database.

What The Command Does

  1. Connects to the source environment via SSH.
  2. Copies all files to the destination environment.
  3. Extracts the database and imports it into the destination database.
  4. (If WordPress): Updates database connection credentials in the site’s configuration files.

Advanced Usage & Modifications

As mentioned earlier, if you’re not using WordPress, 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 want to override where the files should be fetched from or placed, you can do so with the --src and --dest parameters:

 $ sitecopy from@old.host newDatabase \
 --src=my/secret/folder \
 --dest=my/new/secret/folder

By default, Sitecopy will use the environment’s web root directory as the source and destination directory, which is ~/site/public.

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 from@old.host 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:

Image displaying an overview of available options in the Sitecopy script.

Further Reading


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