How I Use Craft Scripts in Craft CMS Running in Craft Nitro 2
Published , updated
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.
Craft Nitro was discontinued on June 28, 2022. Read the official blog post titled Retiring Craft Nitro to learn more.
- Craft 3.6.x, or later 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.
From your Craft project's root directory on your host machine, run:
nitro ssh --rootto SSH into project's container as the root user.
apk add bashto install the Alpine Linux bash shell package.
apk add rsyncto install the Alpine Linux rsync package.
apk add openssh-clientto install the Alpine Linux OpenSSH client package.
exitto exit as root user.
nitro sshto ssh into container.
bash pull_assets.sh, from your
scriptsdirectory to pull down assets from remote production/staging environment.
bash pull_db.shfrom within your
scriptsdirectory 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 xon|xoff, or
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.