Code Monkey home page Code Monkey logo

Comments (7)

khalwat avatar khalwat commented on June 2, 2024 4

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.

from craft-scripts.

khalwat avatar khalwat commented on June 2, 2024 1

@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.

from craft-scripts.

khalwat avatar khalwat commented on June 2, 2024

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

from craft-scripts.

shornuk avatar shornuk commented on June 2, 2024

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?

from craft-scripts.

chasegiunta avatar chasegiunta commented on June 2, 2024

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

from craft-scripts.

sjelfull avatar sjelfull commented on June 2, 2024

Naah, I did not. Someday 😬

from craft-scripts.

callaginn avatar callaginn commented on June 2, 2024

@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

from craft-scripts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.