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

Add push_db #6

Open
sjelfull opened this issue Feb 26, 2017 · 7 comments
Open

Add push_db #6

sjelfull opened this issue Feb 26, 2017 · 7 comments

Comments

@sjelfull
Copy link
Contributor

When developing a site locally, I usually push to staging all the time. Do you have a script for pushing to remote already, or should I send you a pull request?

@khalwat
Copy link
Contributor

khalwat commented Feb 26, 2017

The workflow I use for that is I have Forge set up to auto-deploy when pushed to the staging or develop branch of my Git repo.

So I don't really need a script to do that; if you want to then pull the db from local to staging, you could either set up the config on the staging server to pull the db from your local dev, or yeah, you could make a push_db script analogous to the pull_db script that would do the opposite.

Pull requests would be awesome if you do decide to make a push_db script; it should be quite simple to do by modifying the pull_db script.

@khalwat
Copy link
Contributor

khalwat commented Feb 26, 2017

If you do, you might also want to make an analogous push_assets script as well.

@shornuk
Copy link

shornuk commented Oct 5, 2017

Has anything happened with this? I may be misunderstanding how these scripts should be utilised, but our current setup is production branch connected to master db. All changes to the database are made on the master, then the scripts pulls the db and assets down locally to my local env. Now we have a staging env as well, so ideally I'd like to pull the master db and assets down to this env, or push them up from my local to it as it's essentially the same. Is this currently possible?

@khalwat
Copy link
Contributor

khalwat commented Oct 6, 2017

@shornuk you should try using a workflow as described here:

https://nystudio107.com/blog/database-asset-syncing-between-environments-in-craft-cms

You absolutely can pull the db & assets to your staging environment; just set up a .env.sh for that environment as well.

@chasegiunta
Copy link

@sjelfull did you ever work up a workflow for pushing_db & push_assets? 😬

@sjelfull
Copy link
Contributor Author

sjelfull commented Sep 7, 2018

Naah, I did not. Someday 😬

@callaginn
Copy link

callaginn commented Dec 14, 2018

@chasegiunta @sjelfull Anyone think this would work for pushing the local database to the remote database? I tried to plug into their scripts and variables as much as possible. This has been tested in pieces, but not as a whole. I'm about 99% sure it should work, but 1% of me still thinks it will crash everything : P

One of my main concerns is that running the remote restore_db.sh script will overwrite local variables with remote variables. I'm still setting up the remote *.env.sh file, so am not sure if this will create issues. Should be able to test for this issue later this week with "echo" statements.

push_db.sh

#!/bin/bash

# Get the directory of the currently executing script
DIR="$(dirname "${BASH_SOURCE[0]}")"

# Include files
INCLUDE_FILES=(
    "common/defaults.sh"
    ".env.sh"
    "common/common_env.sh"
    "common/common_db.sh"
)

for INCLUDE_FILE in "${INCLUDE_FILES[@]}"; do
    if [[ ! -f "${DIR}/${INCLUDE_FILE}" ]] ; then
        echo "File ${DIR}/${INCLUDE_FILE} is missing, aborting."
        exit 1
    fi
    source "${DIR}/${INCLUDE_FILE}"
done

# Backup local database:
./backup_db.sh

# Set the backup db file name, parent directory path, and full path
BACKUP_DB_DIR_PATH="${LOCAL_BACKUPS_PATH}${LOCAL_DB_NAME}/${DB_BACKUP_SUBDIR}/"
BACKUP_DB_NAME="$(basename $(ls -t $BACKUP_DB_DIR_PATH*.sql* | head -1))";
BACKUP_DB_PATH="${BACKUP_DB_DIR_PATH}${BACKUP_DB_NAME}";

# Copy local backup to server:
echo "*** Copying $BACKUP_DB_PATH to $REMOTE_BACKUPS_PATH$BACKUP_DB_NAME";
scp "$BACKUP_DB_PATH" "$REMOTE_SSH_LOGIN:$REMOTE_BACKUPS_PATH$BACKUP_DB_NAME";

# Log into server and restore local backup
ssh -t $REMOTE_SSH_LOGIN << EOF
"${REMOTE_ROOT_PATH}scripts/restore_db.sh" "$REMOTE_BACKUPS_PATH$BACKUP_DB_NAME";
EOF

# Normal exit
exit 0

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

No branches or pull requests

5 participants