Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow syncdb to be used to sync db from all existing envs #24

Open
hkirsman opened this issue Apr 23, 2024 · 0 comments
Open

Allow syncdb to be used to sync db from all existing envs #24

hkirsman opened this issue Apr 23, 2024 · 0 comments

Comments

@hkirsman
Copy link
Collaborator

hkirsman commented Apr 23, 2024

This is my current new code:

#!/bin/bash

#
# Synchronise local database with the production environment.
#
# Based on https://github.com/wunderio/unisport/blob/master/.lando/syncdb.sh
#

set -eu
if [[ -n "${WUNDERIO_DEBUG:-}" ]]; then
    set -x
fi
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin

source .ddev/wunderio/core/_helpers.sh

# Pass drush alias as argument and sync the database
# from the remote environment to the local environment.
sync_database_from() {
    alias=$1

    sql_file="$alias-syncdb-$(date +'%Y-%m-%d').sql"

    alias_entry=$(ddev drush sa @$alias)
    ssh_user=$(echo "$alias_entry" | ddev yq '.\"@self.'$alias'\".user' )
    ssh_options=$(echo "$alias_entry" | ddev yq '.\"@self.'$alias'\".ssh.options' )
    ssh_host=$(echo "$alias_entry" | ddev yq '.\"@self.'$alias'\".host' )

    set -x
    # For some reason "ddev drush sql-sync @your-alias @local -y" does not work and times out
    # so we have to do this with sql-dump.
    ssh "$ssh_user@$ssh_host" "$ssh_options" "drush sql-dump --structure-tables-list=cache,cache_*,history,search_*,sessions" > "$sql_file"
    ddev import-db --file="$sql_file"
    #rm "$sql_file"
    { set +x; } 2>/dev/null

    display_status_message "Sync complete!"
}

sync_database_from $1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant