mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-23 20:26:49 +00:00
The old script was specfic to the use in Australia and out of date. The new version isn't perfect but works well for me.
52 lines
1.3 KiB
Bash
Executable File
52 lines
1.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Used to pull data from production or staging servers into local dev database
|
|
# Useful for when you want to test a migration against production data, or see
|
|
# the effect of codebase changes on real-life data
|
|
|
|
set -e
|
|
|
|
HOST="$1"
|
|
BUCKET="$2"
|
|
: ${DB_USER='ofn_user'}
|
|
: ${DB_DATABASE='openfoodnetwork'}
|
|
|
|
DB_OPTIONS=(
|
|
--exclude-table-data=sessions
|
|
--exclude-table-data=spree_log_entries
|
|
--exclude-table-data=spree_state_changes
|
|
--no-acl
|
|
)
|
|
|
|
if [ -z "$HOST" ]; then
|
|
echo "[Error] SSH host missing.
|
|
Usage: $0 openfoodnetwork@openfoodnetwork.org.au" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if hash zeus 2>/dev/null && [ -e .zeus.sock ]; then
|
|
RAILS_RUN='zeus r'
|
|
else
|
|
RAILS_RUN='bundle exec rails runner'
|
|
fi
|
|
|
|
# -- Mirror database
|
|
echo "Mirroring database..."
|
|
dropdb -h localhost -U ofn open_food_network_dev
|
|
createdb -h localhost -U ofn open_food_network_dev
|
|
ssh -C "$HOST" "pg_dump -h localhost -U $DB_USER $DB_DATABASE ${DB_OPTIONS[@]}" | psql -h localhost -U ofn open_food_network_dev
|
|
|
|
# -- Disable S3
|
|
echo "Preparing mirrored database..."
|
|
$RAILS_RUN script/prepare_imported_db.rb
|
|
|
|
# -- Mirror images
|
|
if [ -n "$BUCKET" ] && hash aws 2>/dev/null; then
|
|
echo "Mirroring images..."
|
|
aws s3 sync "s3://$BUCKET/public public/"
|
|
|
|
else
|
|
echo "Please install the AWS CLI tools so that I can copy the images from $BUCKET for you."
|
|
echo "eg. sudo easy_install awscli"
|
|
fi
|