Adobe Commerce Cloud - Transfer files between two different projects
Goal
The goal is to transfer files between two separate projects.
Assumptions
You will need two projects set up on Magento Cloud:
One project (zbeyezwn4jwlw in this guide) that acts as the data source. One project (xkpilazn78kkq) that is the data sink (where we want to copy data to).
Problems
Communication between projects relies on SSH, so managing the keys needs to be automated.
Steps
1. Preparing the data sink
On the data sink, add .ssh as a writeable mount (this is to allow SSH to write into known_hosts). Your .magento.app.yaml
has to contain this block:
mounts:
"/.ssh":
source: local
source_path: .ssh
In the build hook, install the Magento Cloud CLI. This is used to dynamically retrieve the data source’s SSH connection string. If the remote will not change, you can also hardcode the path and avoid this step.
hooks:
build: |
echo "### INSTALLING Magento Cloud CLI ... ###"
curl -sS https://accounts.magento.cloud/cli/installer | php
2. Create API Token
- Go to https://accounts.magento.cloud/
- Navigate the tab "Account settings" > API Tokens
- Create and save a token
3. Transferring files
Connect to the data sink project using the -A option for SSH (this allows SSH key forwarding and connections to the data source project from the data sink project):
> ssh -A "$(magento-cloud ssh -p xkpilazn78kkq -e staging --pipe)"
__ __ _ ___ _ _
| \/ |__ _ __ _ ___ _ _| |_ ___ / __| |___ _ _ __| |
| |\/| / _` / _` / -_) ' \ _/ _ \ | (__| / _ \ || / _` |
|_| |_\__,_\__, \___|_||_\__\___/ \___|_\___/\_,_\__,_|
|___/
Welcome to Magento Cloud.
This is server i-15da8dd0491ed2fc2, role xkpilazn78kkq.dev:unified.
Log in to Magento Cloud from the data sink project using the API token created in step 2.
> magento-cloud auth:api-token-login
Now you can run magento-cloud scp
command
xkpilazn78kkq_stg@i-15da8dd0491ed2fc2:~$ magento-cloud scp -r -p xkpilazn78kkq -e staging remote:pub/media/banner pub/media/
Warning: Permanently added 'ssh.eu-8.magento.cloud (24.141.74.191)' (RSA) to the list of known hosts.
Banner_2_for_20_11.jpg 100% 1998 96.3KB/s 00:00
Banner_2_for_20_1_12.jpg 100% 1998 97.3KB/s 00:00
Banner_2_for_20_445.jpg 100% 1998 103.4KB/s 00:00
Banner_2_for_20_2.jpg 100% 1998 108.7KB/s 00:00
Banner_3_for_20_213.jpg 100% 3615 194.7KB/s 00:00
Banner_2_for_20_334.jpg 100% 1998 109.4KB/s 00:00
xkpilazn78kkq_stg@i-15da8dd0491ed2fc2:~$
There is also an option to run rsync command if needed
rsync -avrz "$(magento-cloud ssh -p xkpilazn78kkq -e staging --pipe)":pub/media/amasty pub/media/
Subscribe to my newsletter
Read articles from Igor S directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by