読者です 読者をやめる 読者になる 読者になる

pg_backup.sh

週5で圧縮しながらローテートするスクリプト



pgsql_backup_logrotate.sh



#! /bin/sh

DAYS=5

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export PATH

# delete
while read line
do
[ -n "${line}" -a -f "${line}" ] || continue

lsof ${line} && continue

rm -f ${line}
done << EOD
`nice find /usr/local/pgsql/backup -type f -maxdepth 1 -mtime ${DAYS} \
-name "*.dump.[0-9]*.gz"`
EOD


# gzip
while read line
do
[ -f "${line}" ] || continue

lsof ${line} && continue

# check file type
[ $(file ${line} | grep "gzip compressed data" | wc -l) -ne 0 ] && continue

nice gzip ${line}
done << EOD
`nice find /usr/local/pgsql/backup -type f -maxdepth 1 | egrep ".*.dump.[0-9]*$"`
EOD