Skip to content

Instantly share code, notes, and snippets.

@joostvanveen
Created December 13, 2017 08:35
Show Gist options
  • Save joostvanveen/c7c38dccea1b12954b841c91bb5fd961 to your computer and use it in GitHub Desktop.
Save joostvanveen/c7c38dccea1b12954b841c91bb5fd961 to your computer and use it in GitHub Desktop.
Crude bash script to Rsync source folder to destination folder, only certain folders and files
#!/usr/bin/env bash
# Magento 2 Deployment Script
# Author: Joost van Veen
usage="$(basename "$0") [-h] source-directory destination-directory folders-to-sync files-to-sync
Rsync folders and files from one folder to another
where:
-h show this help text
source-directory (required) The absolute path to the source folder
destination-directory (required) The absolute path to the destination folder
folders-to-sync (required) A space separated list of folders to rsync, surrounded by double quotes, with a trailing slash for each folder. E.g. \"app/ bin/ dev/ lib/ pub/errors/ pub/media/amasty/ pub/media/theme/ pub/media/theme_customization/ pub/opt/ pub/static/ phpserver/ setup/ update/ vendor/\"
files-to-sync (required) A space separated list of files and file types to rsync, surrounded by double quotes. E.g. \"*.php *.txt *.html *.sh *.ini *.json .htaccess\"
"
while getopts ':h' option; do
case "$option" in
h) echo "$usage"
exit
;;
\?) printf "illegal option: -%s\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
esac
done
SOURCE_DIR=$1
DESTINATION_DIR=$2
FOLDERS_TO_RSYNC=$3
FILES_TO_RSYNC=$4
echo "FOLDERS_TO_RSYNC: " $FOLDERS_TO_RSYNC
echo "FILES_TO_RSYNC: " $FILES_TO_RSYNC
echo "Syncing files to "$SOURCE_DIR
cd $SOURCE_DIR
for i in $FILES_TO_RSYNC; do
rsync -aq $SOURCE_DIR/${i} $DESTINATION_DIR/;
done
echo "Syncing folders to "$SOURCE_DIR
for i in $FOLDERS_TO_RSYNC; do
mkdir -p $DESTINATION_DIR/${i};
rsync -aq --delete $SOURCE_DIR/${i} $DESTINATION_DIR/${i};
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment