Skip to content

Instantly share code, notes, and snippets.

@encima
Created November 6, 2023 13:09
Show Gist options
  • Save encima/ce21473129ff4027c6eccce5d271d2b1 to your computer and use it in GitHub Desktop.
Save encima/ce21473129ff4027c6eccce5d271d2b1 to your computer and use it in GitHub Desktop.
Supabase DB Inspect Snapshot (requires Supabase CLI)
#!/bin/zsh
# Run as ./inspect_snapshot.sh $DB_URI $OUTPUT_DIR
inspect_help=$(supabase inspect db -h)
cmds=("${(@f)$(echo "$inspect_help" | awk '/^[[:space:]]{2}[[:alpha:]]+/{print $1}')}")
shift cmds #remove supabase at index 0
current_date=$(date +%F)
output_dir=$2
# Check if output directory exists, if not, create it
mkdir -p "$output_dir"
for cmd in $cmds; do
output_file="${output_dir}/${cmd}_${current_date}.txt"
# Execute the supabase inspect subcommand and save the output
supabase inspect db --db-url "$1" "$cmd" >"$output_file"
# Confirm success
if [ $? -eq 0 ]; then
echo "Successfully inspected ${cmd} on ${current_date}."
else
echo "Failed to inspect ${cmd} on ${current_date}."
fi
done
echo "Inspection completed. Results are saved in ${output_dir}."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment