Skip to content

Instantly share code, notes, and snippets.

@lionslair
Last active February 12, 2026 00:34
Show Gist options
  • Select an option

  • Save lionslair/19f526e960d851c2a51c84f677b06d81 to your computer and use it in GitHub Desktop.

Select an option

Save lionslair/19f526e960d851c2a51c84f677b06d81 to your computer and use it in GitHub Desktop.
gets rid of all useless inserts in downloaded sql dumps
#!/bin/bash
# Check if the script received an argument
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <sql_file>"
exit 1
fi
# Check if the file exists
if [ ! -f "$1" ]; then
echo "File not found!"
exit 1
fi
# Remove the insert statements
sed -i.bak \
-e '/INSERT INTO `sessions`/d' \
-e '/INSERT INTO `pulse_aggregates`/d' \
-e '/INSERT INTO `pulse_entries`/d' \
-e '/INSERT INTO `pulse_values`/d' \
-e '/INSERT INTO `failed_jobs`/d' \
-e '/INSERT INTO `queue_failed_jobs`/d' \
-e '/INSERT INTO `xero_tokens`/d' \
-e '/INSERT INTO `daily_task_statuses`/d' \
-e '/INSERT INTO `logs`/d' \
-e '/INSERT INTO `app_logs`/d' \
-e '/INSERT INTO `subcontractor_driver_messages`/d' \
-e '/INSERT INTO `business_central_sync_logs`/d' \
-e '/INSERT INTO `activity_logs`/d' \
-e '/^CREATE DATABASE /Id' \
-e '/^USE /Id' \
-e 's/DEFINER=[^*]*\*/\*/' \
-e 's/DEFINER=[^ ]* //' \
"$1"
echo "Operation completed. The original file was backed up with a .bak extension."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment