Created
May 15, 2024 22:29
-
-
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
This file contains 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
#!/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