This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
forked from Varying-Vagrant-Vagrants/VVV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pull-production.sh
executable file
·106 lines (79 loc) · 3.96 KB
/
pull-production.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
set -eox pipefail # verbose output, should also stop script if something fails
if [ "$1" = "-h" ]; then
echo "Usage information for pull-production.sh:"
echo ""
echo "Development environment update script for syncing database and files from"
echo "production to local development environment."
echo ""
echo "Depends on rsync and production ssh key and ssh connection setup"
echo "and public_html path aliased to script directory."
echo ""
echo "Syntax:"
echo ""
echo "pull-production.sh"
echo "pull-production.sh -h # prints this message"
exit 1
fi
# check if "jonne" ssh-host exists in ~/.ssh/config
if ! grep -q "Host jonne" ~/.ssh/config; then
echo "Error: ssh host 'jonne' not found in ~/.ssh/config consult README.md or modify script"
exit 1
fi
# Eg. in ~/.ssh/config
# Host jonne
# hostname <SSH HOSTNAME HERE!>
# user <SSH USERNAME HERE!>
# port <SSH PORT HERE!>
PROD_SSH_HOST=jonne
PROD_WWW_PATH=/var/sites/jkl.hacklab.fi
PROD_DOMAIN=jkl.hacklab.fi
DEV_DOMAIN=jkl.hacklab.test
VAGRANT_WWW_PATH=/srv/www/hacklab-jkl/public_html
# Change cwd to this script file's path
cd $(dirname "$0")
# Check if path ./public_html (custom setup) or ./www/hacklab-jkl/public_html (default VVV sub-path) exists
if [ -d "./public_html" ]; then
echo "Found ./public_html assuming it as WP www-root."
LOCAL_WWW_PATH=./public_html
elif [ -d "./www/hacklab-jkl/public_html" ]; then
echo "Found WP from default VVV path ./www/hacklab-jkl/public_html, assuming it as WP www-root."
LOCAL_WWW_PATH=./www/hacklab-jkl/public_html
else
echo "Error: WP www-root not found, something is off with the vvv dev environment"
exit 1
fi
echo "cd'ing to local WP www-root"
cd $LOCAL_WWW_PATH
echo "Downloading PROD wp-content files, deleting local files that don't exist on PROD"
# --delete cleans target from files missing from source, eg. .git will be overwritten
rsync -av --delete $PROD_SSH_HOST:$PROD_WWW_PATH/wp-content .
# --exclude 'uploads' --exclude 'object-cache.php' --exclude 'mu-plugins/' # these may be useful some times
echo 'Exporting PROD database'
ssh $PROD_SSH_HOST "wp --path=$PROD_WWW_PATH db export wpdb.sql && cat wpdb.sql | gzip > wpdb.sql.gz && rm wpdb.sql"
echo 'Downloading database export'
# --remove-source-files removes the wpdb.sql.gz from source after copy to keep things clean
rsync -av --progress --remove-source-files $PROD_SSH_HOST:~/wpdb.sql.gz .
gzip -d -f wpdb.sql.gz
# Check if ./public_html/wp-config.php exists, and try create if not
if [ ! -f "wp-config.php" ]
then
echo "Error: wp-config.php not found, something is off with the vvv dev environment"
echo "create with eg:"
echo 'vagrant ssh -c "cd $VAGRANT_WWW_PATH && wp config create --dbname=hacklab --dbuser=wp --dbpass=wp"'
echo "Trying..."
vagrant ssh -c "cd $VAGRANT_WWW_PATH && wp config create --dbname=hacklab --dbuser=wp --dbpass=wp"
fi
echo "Importing database into vagrant box"
vagrant ssh -c "wp --path=$VAGRANT_WWW_PATH db drop --yes"
vagrant ssh -c "wp --path=$VAGRANT_WWW_PATH db create"
vagrant ssh -c "wp --path=$VAGRANT_WWW_PATH db import $VAGRANT_WWW_PATH/wpdb.sql"
echo "Running search & replace, deactivating PROD-only plugins etc."
vagrant ssh -c "wp --path=$VAGRANT_WWW_PATH search-replace "//jkl.hacklab.fi" "//$DEV_DOMAIN" --skip-plugins"
vagrant ssh -c "wp --path=$VAGRANT_WWW_PATH search-replace "//jyväskylä.hacklab.fi" "//$DEV_DOMAIN" --skip-plugins"
vagrant ssh -c "wp --path=$VAGRANT_WWW_PATH search-replace "//xn--jyvskyl-7wae.hacklab.fi" "//$DEV_DOMAIN" --skip-plugins"
vagrant ssh -c "wp --path=/srv/www/hacklab-jkl/public_html search-replace \"https://\" \"http://\" --dry-run" # comment this to use https
vagrant ssh -c "wp --path=$VAGRANT_WWW_PATH option update admin_email "dev-email@flywheel.test" --skip-plugins"
vagrant ssh -c "wp --path=$VAGRANT_WWW_PATH cache flush --skip-plugins"
vagrant ssh -c "wp --path=$VAGRANT_WWW_PATH plugin install --activate debug-bar debug-bar-timber --skip-plugins"
echo "Sync complete, access via http://$DEV_DOMAIN"