Skip to content

Instantly share code, notes, and snippets.

@otoayana
Created May 15, 2024 22:29
Show Gist options
  • Save otoayana/7623d05b0b60c71160c37771398bfcaf to your computer and use it in GitHub Desktop.
Save otoayana/7623d05b0b60c71160c37771398bfcaf to your computer and use it in GitHub Desktop.
Simple tool for PostgreSQL database recovery. Finds missing pages in database and touches them
#!/bin/bash
# Set parameters before running
DATA=/var/lib/postgresql/15/data
HOST=/tmp
PORT=5433
DB=database
USER=postgres
FILE=$1
echo "pg_taprec"
echo "© 2024 Lux Aliaga, Licensed under GPLv3"
if [ -z "${FILE}" ]; then
echo "Specify an output file before continuing!"
exit 1
fi
while true; do
DUMP=$(pg_dump -h ${HOST} -p ${PORT} -U ${USER} ${DB} -f ${FILE} 2>&1 > /dev/null | grep -w "could not open file" | cut -d '"' -f2)
if [ -z "${DUMP}" ]; then
echo "No more pages to touch. Exiting..."
break
else
echo "Creating blank page \"${DUMP}\"..."
touch ${DATA}/${DUMP}
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment