How I Use Craft Scripts in Craft CMS Running in Craft Nitro 2

In this article, I explain how I use Craft Scripts in my Nitro 2 local development environment to pull down user-generated assets and the Craft database from a remote Craft CMS production environment.

Assumptions

  • Craft 3.6.x running in in Craft Nitro 2.0.8 in a local development environment. The instructions below may or may not work in earlier and/or later versions of Craft and/or Nitro 2.x.

  • Craft Scripts 1.2.13, or later.

Instructions

From your Craft project's root directory on your host machine, run:

  1. nitro ssh --root to SSH into project's container as the root user.

  2. apk add bash to install the Alpine Linux bash shell package.

  3. apk add rsync to install the Alpine Linux rsync package.

  4. apk add openssh-client to install the Alpine Linux OpenSSH client package.

  5. exit to exit as root user.

  6. nitro ssh to ssh into container.

  7. bash pull_assets.sh, from your scripts directory to pull down assets from remote production/staging environment.

  8. bash pull_db.sh from within your scripts directory to pull down the Craft database from remote production/staging environment.

System changes made as the root user are ephemeral, so you'll need to repeat steps 1-4 every time Nitro recreates the site's container after you run nitro applynitro xon|xoff, or nitro update.

That's it! By following the steps above, I can pull down user-generated assets and the Craft database from a remote Craft CMS production environment into my Nitro 2 local development environment.