Last active
November 10, 2025 05:46
-
-
Save manishsongirkar/9f65d68c4647a72bc9de46cde7329d0f to your computer and use it in GitHub Desktop.
Download the database using WordPress VIP CLI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| download_vip_db() { | |
| echo "Fetching application list from VIP CLI using 'vip app list'..." | |
| # Run VIP app list and remove ANSI color codes | |
| local APP_OUTPUT | |
| APP_OUTPUT=$(vip app list 2>/dev/null) | |
| if [ $? -ne 0 ] || [[ -z "$APP_OUTPUT" ]]; then | |
| echo "❌ Error: Failed to execute 'vip app list'. Make sure you're logged in with 'vip login'." | |
| return 1 | |
| fi | |
| # Strip ANSI color codes like [39m or [90m | |
| APP_OUTPUT=$(echo "$APP_OUTPUT" | sed -E 's/\x1B\[[0-9;]*[A-Za-z]//g; s/\[[0-9]{1,3}m//g') | |
| # Extract application ID and name into simple "ID | Name" list | |
| local APPS | |
| APPS=$(echo "$APP_OUTPUT" \ | |
| | grep '│' \ | |
| | grep -v -E 'id|NAME|───' \ | |
| | awk -F'│' '{id=$2; name=$3; gsub(/^[ \t]+|[ \t]+$/, "", id); gsub(/^[ \t]+|[ \t]+$/, "", name); if (id && name) print id " | " name}') | |
| # Fallback for alternate CLI formats | |
| if [[ -z "$APPS" ]]; then | |
| APPS=$(echo "$APP_OUTPUT" | awk 'NR>2 {print $1 " | " $2}' | grep -v -E 'id|repo|NAME') | |
| fi | |
| if [[ -z "$APPS" ]]; then | |
| echo "❌ Error: Could not extract application list." | |
| echo "Raw output was:" | |
| echo "$APP_OUTPUT" | |
| return 1 | |
| fi | |
| # Check for fzf | |
| if ! command -v fzf &>/dev/null; then | |
| echo "❌ 'fzf' is required. Install it with 'brew install fzf' on MacOS." | |
| return 1 | |
| fi | |
| echo "Select VIP Application:" | |
| local CHOSEN_LINE | |
| CHOSEN_LINE=$(echo "$APPS" | fzf \ | |
| --style full \ | |
| --input-label " Type Application Name " \ | |
| --prompt "Select VIP Application: " \ | |
| --height=40% \ | |
| --border=rounded \ | |
| --margin=1 \ | |
| --cycle \ | |
| ) | |
| if [[ -z "$CHOSEN_LINE" ]]; then | |
| echo "❌ No application selected. Exiting." | |
| return 0 | |
| fi | |
| # Extract the application name (right of the '|') | |
| local CHOSEN_APP | |
| CHOSEN_APP=$(echo "$CHOSEN_LINE" | awk -F'|' '{gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2}') | |
| local OUTPUT_FILE="./${CHOSEN_APP}-db-$(date +%Y%m%d_%H%M%S).sql.gz" | |
| echo "" | |
| echo "=================================================================" | |
| echo " Starting VIP Database Export" | |
| echo "=================================================================" | |
| echo " Application: @$CHOSEN_APP" | |
| echo " Output File: $OUTPUT_FILE" | |
| echo " Command: vip \"@$CHOSEN_APP\" export sql --output=\"$OUTPUT_FILE\"" | |
| echo "=================================================================" | |
| echo "" | |
| # ✅ Just run export directly (let VIP CLI handle environment prompt) | |
| vip "@$CHOSEN_APP" export sql --output="$OUTPUT_FILE" | |
| if [ $? -eq 0 ]; then | |
| echo "" | |
| echo "✅ Database export completed successfully!" | |
| echo "File saved to: $OUTPUT_FILE" | |
| else | |
| echo "" | |
| echo "❌ VIP CLI command failed. Check the error message above." | |
| return 1 | |
| fi | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment