Created
July 11, 2020 07:41
-
-
Save accentinteractive/220ac5a9d8f9959bb71675be2deca9f2 to your computer and use it in GitHub Desktop.
This command line script will download the entire Magento 2 media folder in seconds, and exclude the dreaded cache and tmp folders. You can use it to download a media folder to your local filesystem or sync media folders between servers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Download all media from the production server, except for cached files. | |
# SET VARIABLES HERE | |
# 1. SSH connection | |
SSH_PRIVATE_KEY="~/.ssh/YOURPRIVATEKEY" | |
SSH_PORT=22 | |
SSH_USER="YOURUSER" | |
SSH_HOST="YOURSERVER.COM" | |
# 2. Paths. Include a trailing slash! | |
REMOTE_PATH="/remote/path/to/magento2/pub/media/" | |
LOCAL_PATH="/local/path/to/magento2/pub/media/" | |
# 3. Paths and files to exclude, separated by a space. You can also include files | |
EXCLUDED_FILES="catalog/product/cache images/cache sitemap tmp" | |
EXCLUDED_FILES_FILENAME="excluded-media-files.txt" | |
# DO NOT EDIT BELOW THIS POINT | |
printf '%s\n' $EXCLUDED_FILES > $EXCLUDED_FILES_FILENAME | |
rsync -arve "ssh -p $SSH_PORT -i $SSH_PRIVATE_KEY" $SSH_USER@$SSH_HOST:$REMOTE_PATH $LOCAL_PATH --exclude-from $EXCLUDED_FILES_FILENAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment