Last active
December 30, 2016 15:21
-
-
Save sebastianwebber/aadce976e996993ce43c22d0d0e2d00d to your computer and use it in GitHub Desktop.
wal_prefetch.sh: Script pra agilizar a cópia do `restore_command`, trazendo vários arquivos de cada vez
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 | |
# Ideia original do @matheusoliveira | |
# $1 é %f, $2 é %p | |
## IMPORTANTE: Lembrar de configurar o `archive_cleanup_command` no `recovery.conf` pra | |
## chamar o pg_archivecleanup e apontar pro ${CACHE_DIR} | |
## exemplo: | |
### restore_command = '/opt/resources/wal_prefetch.sh %f %p' | |
### archive_cleanup_command = '/usr/pgsql-9.3/bin/pg_archivecleanup /slave/wal-cache %r' | |
MAX_FILES=25 | |
REMOTE_DIR='/dados/archive_log' | |
CACHE_DIR='/slave/wal-cache' | |
WAL_FILE="${1}" | |
WAL_PATH="${2}" | |
if [ -f ${CACHE_DIR}/${WAL_FILE}.gz ]; then | |
zcat ${CACHE_DIR}/${WAL_FILE}.gz > ${WAL_PATH} | |
exit $? | |
else | |
file_list="/tmp/file_list.txt" | |
rm -f ${file_list} | |
ssh server "ls -lto ${REMOTE_DIR}" | grep -B ${MAX_FILES} ${WAL_FILE} | awk '{print $NF}' > ${file_list} | |
rsync -a --files-from="${file_list}" server:"${REMOTE_DIR}" "${CACHE_DIR}" | |
zcat ${CACHE_DIR}/${WAL_FILE}.gz > ${WAL_PATH} | |
exit $? | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment