6

Is there a way export media files from Magento Cloud to local machine ? I have setup and magento 2 cloud website but I don't get the product images and other media files.

4 Answers 4

8

Magento devdoc suggests to use rsync to move media files. https://devdocs.magento.com/guides/v2.3/cloud/live/stage-prod-migrate.html

To migrate static files from your local machine:

Use the rsync command to copy the pub/media directory from your local Magento server to staging or production:

rsync -azvP local_machine/pub/media/ <[email protected]>:pub/media/

In your case, reverse the rsync source & destination of above command.

3
  • 8
    This is a bit of a dangerous answer for anyone not reading it fully, you can wipe out production if you just run this blindly.. The reverse order is the correct one and the one that correctly answers the question
    – Alberto
    Commented Oct 22, 2019 at 21:44
  • Can you please tell what is right syntax to export medial from live to local?
    – Ramesh KR
    Commented Apr 3, 2020 at 19:04
  • Don't forget to run bin/magento media-gallery:sync to sync all media from the filesystem to the database (see media_gallery_asset table) Commented Jan 26, 2022 at 7:43
5

You can use magento cloud cli

cli setup : https://devdocs.magento.com/cloud/reference/cli-ref-topic.html

Usage:
 magento-cloud scp [-r|--recursive] [-p|--project PROJECT] [--host HOST] [-e|--environment ENVIRONMENT] [-A|--app APP] [--worker WORKER] [-i|--identity-file IDENTITY-FILE] [--] [<files>]...

Arguments:
  files                              Files to copy. Use the remote: prefix to define remote locations.

Options:
  -r, --recursive                    Recursively copy entire directories
  -p, --project=PROJECT              The project ID or URL
      --host=HOST                    The project's API hostname
  -e, --environment=ENVIRONMENT      The environment ID
  -A, --app=APP                      The remote application name
      --worker=WORKER                A worker name
  -i, --identity-file=IDENTITY-FILE  An SSH identity (private key) to use
  -h, --help                         Display this help message
  -q, --quiet                        Do not output any message
  -V, --version                      Display this application version
  -y, --yes                          Answer "yes" to any yes/no questions; disable interaction
  -n, --no                           Answer "no" to any yes/no questions; disable interaction
  -v|vv|vvv, --verbose               Increase the verbosity of messages

Examples:
 Copy local files a.txt and b.txt to remote mount var/files:
   magento-cloud scp a.txt b.txt remote:var/files

 Copy remote files c.txt to current directory:
   magento-cloud scp remote:c.txt .

 Copy subdirectory dump/ to remote mount var/files:
   magento-cloud scp -r dump remote:var/logs

 Copy files inside subdirectory dump/ to remote mount var/files:
   magento-cloud scp -r dump/* remote:var/logs
5

It's so easy!

Check this

 magento-cloud mount:download --help

And try to execute

magento-cloud mount:download --mount pub/media --target=pub/media -p my-project-name -e my-m2cloud-branch 
5

For me the easiest command is:
magento-cloud scp remote:your/remote/file.jpg ./your/local/destination

at example i want to get all media from pub/media:
magento-cloud scp remote:pub/media/* ./pub/media


then it asks to provide an eviroment (in my case production)
that's it 😉 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.