Skip to content

Instantly share code, notes, and snippets.

@gwillem
Last active October 18, 2016 21:04
Show Gist options
  • Save gwillem/0a5894ac44ba82cd9d7b to your computer and use it in GitHub Desktop.
Save gwillem/0a5894ac44ba82cd9d7b to your computer and use it in GitHub Desktop.
Create Hypernode copy of live site
# is there enough space?
DBNAME=$(magerun --root-dir=~/public db:info dbname)
USAGE_FILE=$(( ( $(du -s --exclude=public/media/\* ~/public | cut -f1) - $(du -s --exclude=public/media/\* ~/staging | cut -f1) ) / 1024 ))
USAGE_DB=$(( $(du -s --exclude= /data/mysql/$DBNAME | cut -f1) / 1024 ))
FREE_SPACE_PRE=$(( $(stat -f --format='%a*%S/1024' ~/public) / 1024 ))
FREE_SPACE_POST=$(( $FREE_SPACE_PRE - $USAGE_FILE - $USAGE_DB ))
# Todo: which db tables to exclude? these: magerun db:dump --stdout --only-command --strip="@stripped" | sed -e 's/ /\n/g' | grep ignore-table | cut -d. -f2
echo "Free $FREE_SPACE_PRE MB, file usage $USAGE_FILE MB, db usage $USAGE_DB MB"
echo "Free space after clone will be $FREE_SPACE_POST MB"
if (( $FREE_SPACE_POST > 500 )); then
echo "Free space after copy ($FREE_SPACE_POST) is more than 500 MB, continuing...";
else
echo "Free space after copy ($FREE_SPACE_POST) would be less than minimum so aborting";
exit 1;
fi
SHOPHOST=shop.byte.nl
rsync -va --delete --delete-excluded \
--exclude /media \
--exclude /var/report/ \
--exclude /var/session/ \
--exclude /var/log/ \
--exclude \*.sql \
--exclude \*.zip \
~/public/ ~/staging/
# Make hardlinks so don't use up space
cp -fvlr ~/public/media ~/staging/
mysql -e 'create database if not exists staging'
cd ~/public
magerun --root-dir=~/public db:dump --strip="@stripped" --stdout | mysql staging
# update local.xml & fpc.xml with new db name ("staging") and other redis db (ie nr 4)
nano ~/staging/app/etc/local.xml
test -e ~/staging/app/etc/fpc.xml && nano ~/staging/app/etc/fpc.xml
cd ~/staging
magerun --root-dir=~/staging config:set web/unsecure/base_url http://$SHOPHOST:10080/
magerun --root-dir=~/staging config:set web/secure/base_url https://$SHOPHOST:10443/
magerun cache:flush
@gwillem
Copy link
Author

gwillem commented Nov 6, 2015

@Nesse: it should not, if you update staging/app/etc/local.xml before running magerun.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment