commit 5cd1a914fc148f18864893cd8a01abae7665e9ef Author: nomadics9 Date: Sun Feb 9 17:22:13 2025 +0300 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fd3981b --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +tmp +oont +wordpress +db diff --git a/README.md b/README.md new file mode 100644 index 0000000..3c11b3b --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# Live to Devlopment environment + +## Usage: +1. Clone this repo and cd into it +``` +git clone https://git.askar.tv/oont/oont-dev +cd oont-dev +``` +2. download Themes, plugins, themes and extract them in oont +### Mac & Linux +``` +curl -o temp.zip 'https://fs.nmd.mov/p/oont/?zip' && unzip temp.zip -d oont && rm temp.zip +``` +### Windows +``` +curl -o temp.zip 'https://fs.nmd.mov/p/oont/?zip' ; Expand-Archive temp.zip -DestinationPath oont ; Remove-Item temp.zip +``` +### Manual Download +``` +https://fs.nmd.mov/p/oont/?zip + +!!Then Extract it into oont directory inside the repo!! +``` +3. Install docker if you dont have it +``` +docker compose up -d +``` + +4. Sync +``` +docker exec -it wp-wordpress-1 sync +``` + +5. Pateience, your local wp should be at +``` +http://localhost:8081 +``` diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..b0f601c --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,43 @@ +services: + + wordpress: + image: wordpress + restart: always + ports: + - 8081:80 + environment: + WORDPRESS_HOME: "http://localhost:8081" # Your local wordpress url + WORDPRESS_SITEURL: "http://localhost:8081" # Your local wordpress url + WORDPRESS_DB_HOST: db # Your local ip address + PROD_DOMAIN: "oont.co" # Live Domain + DEV_DOMAIN: "localhost:8081" # Local wordpress domain + + # Local DB as specified Below + WORDPRESS_DB_USER: exampleuser + WORDPRESS_DB_PASSWORD: examplepass + WORDPRESS_DB_NAME: oont-dev + + # Live remote DB + PROD_DB_HOST: "sql688.your-server.de" + PROD_DB_USER: "wp_oonty_1" + PROD_DB_PASS: "m3B1iEjUcZ318j5W" + PROD_DB_NAME: "wp_oonty_db1" + volumes: + - ./wordpress:/var/www/html + - ./tmp/prod-dump.sql:/tmp/prod-dump.sql + - ./sync-prod-to-dev.sh:/usr/local/bin/sync + - ./wp-cli.phar:/usr/local/bin/wp + - ./oont/:/var/www/oont + + db: + image: mysql:8.0 + restart: always + ports: + - 3306:3306 + environment: + MYSQL_DATABASE: oont-dev + MYSQL_USER: exampleuser + MYSQL_PASSWORD: examplepass + MYSQL_RANDOM_ROOT_PASSWORD: '1' + volumes: + - ./db:/var/lib/mysql diff --git a/sync-prod-to-dev.sh b/sync-prod-to-dev.sh new file mode 100755 index 0000000..773ee80 --- /dev/null +++ b/sync-prod-to-dev.sh @@ -0,0 +1,147 @@ +#!/usr/bin/env bash +# +# sync-prod-to-dev.sh +# +# 1. Dump the Production WordPress DB using mysqldump +# 2. Transfer the dump file to Dev (optional step if needed) +# 3. Import the dump into Dev using mysql +# 4. Use WP-CLI on Dev to run search-replace for the domain +# +# Assumes: +# - You have MySQL credentials for both Prod and Dev +# - WP-CLI is installed on Dev +# - The Dev WordPress site is configured (wp-config.php) in the DEV_WP_PATH +# - SSH is set up between local/Dev and Prod (if they are separate servers) +# +# Note: For dev environment, typical domain is "http://localhost:8080" or "http://dev.example.com". +# +# IMPORTANT: This will overwrite your Dev database each time it's run. +#################################### +# COPY THEMES AND PLUGINS +#################################### +echo "=== Copying Themes, plugins & uploads ===" +cp -r /var/www/oont/themes/ /var/www/html/wp-content +cp -r /var/www/oont/plugins/ /var/www/html/wp-content +cp -r /var/www/oont/uploads /var/www/html/wp-content +cp -r /var/www/oont/uploads-webpc/ /var/www/html/wp-content +#################################### +# 1. CONFIGURE THESE VARIABLES +#################################### + +# --- Production DB --- +PROD_DB_HOST="${PROD_DB_HOST}" +PROD_DB_USER="${PROD_DB_USER}" +PROD_DB_PASS="${PROD_DB_PASS}" +PROD_DB_NAME="${PROD_DB_NAME}" + + +# --- Dev DB --- +DEV_DB_HOST="${WORDPRESS_DB_HOST}" +DEV_DB_USER="${WORDPRESS_DB_USER}" +DEV_DB_PASS="${WORDPRESS_DB_PASSWORD}" +DEV_DB_NAME="${WORDPRESS_DB_NAME}" + + +# Temporary SQL dump file +SQL_FILE="/tmp/prod-dump.sql" + +# Old (production) and New (dev) domain +OLD_DOMAIN="${PROD_DOMAIN}" +NEW_DOMAIN="${DEV_DOMAIN}" + + + +#################################### +# 2. DUMP PRODUCTION DB +#################################### +apt update && apt install mariadb-client +echo -e "\033[31mDo you want to dump the latest DB? [y/N]: \033[0m" +read -n 1 -r +echo # move to a new line + +# Check the response (if the first character is y/Y, proceed) +if [[ "$REPLY" =~ ^[Yy]$ ]]; then + + echo "=== Dumping Production DB from ${PROD_DB_HOST} ===" + mysqldump --single-transaction \ + -h "${PROD_DB_HOST}" \ + -u "${PROD_DB_USER}" \ + -p"${PROD_DB_PASS}" \ + --add-drop-table \ + "${PROD_DB_NAME}" \ + > "${SQL_FILE}" & + + # Capture the PID of the mysqldump job + DUMP_PID=$! + + echo "Mysqldump started (PID: $DUMP_PID). Monitoring file size..." + + # While the dump is still running, show file size every 5 seconds + while kill -0 "$DUMP_PID" 2>/dev/null; do + CURRENT_SIZE=$(du -h "${SQL_FILE}" 2>/dev/null | cut -f1) + echo "Current dump size: $CURRENT_SIZE" + sleep 5 + done + + # Wait for mysqldump to finish (or capture its exit code) + wait "$DUMP_PID" + EXIT_CODE=$? + + if [ $EXIT_CODE -eq 0 ]; then + echo "Dump completed successfully!" + else + echo "Dump failed with exit code $EXIT_CODE" + fi + +else + echo "Skipping database dump." +fi + +#################################### +# 3. IMPORT INTO DEV DB +#################################### +echo "=== Importing dump into Dev DB on ${DEV_DB_HOST} ===" +mysql \ + -h "${DEV_DB_HOST}" \ + -u "${DEV_DB_USER}" \ + -p"${DEV_DB_PASS}" \ + "${DEV_DB_NAME}" \ + < "${SQL_FILE}" + +if [ $? -ne 0 ]; then + echo "ERROR: Failed to import into dev DB." + exit 1 +fi + +#################################### +# 4. SEARCH & REPLACE WITH WP-CLI +#################################### +echo "=== Running WP-CLI search-replace to fix domain: ${OLD_DOMAIN} -> ${NEW_DOMAIN} ===" +cd "${DEV_WP_PATH}" || { + echo "ERROR: Cannot cd into dev WP path: ${DEV_WP_PATH}" + exit 1 +} + +# We do two replacements to handle both http and https references. +# If your production is strictly https, you can remove the http line. +# If your prod is strictly http, you can remove the https line. +# Otherwise, let's do both for completeness. + +# Replace https://OLD_DOMAIN with http://NEW_DOMAIN +php -d memory_limit=512M /usr/local/bin/wp search-replace "https://${OLD_DOMAIN}" "http://${NEW_DOMAIN}" --skip-columns=guid --allow-root +php -d memory_limit=512M /usr/local/bin/wp search-replace "http://${OLD_DOMAIN}" "http://${NEW_DOMAIN}" --skip-columns=guid --allow-root +# If you want your dev site to be https too, adjust accordingly. + +if [ $? -ne 0 ]; then + echo "ERROR: WP-CLI search-replace failed." + exit 1 +fi + +#################################### +# 5. CLEANUP (OPTIONAL) +#################################### +# echo "=== Removing SQL file: ${SQL_FILE} ===" +# rm -f "${SQL_FILE}" +# +echo "=== Done! Your Dev DB is now synced from Prod and domain references updated. ===" + diff --git a/wp-cli.phar b/wp-cli.phar new file mode 100755 index 0000000..a5b9521 Binary files /dev/null and b/wp-cli.phar differ