34 lines
No EOL
740 B
Bash
34 lines
No EOL
740 B
Bash
#!/bin/bash
|
|
|
|
# Edit 2020/04/15
|
|
|
|
user=postgres
|
|
source /home/$user/.bash_profile
|
|
|
|
backup=$PGDATA/../backup
|
|
today=`date +%F`
|
|
aweekago=`date -d -7days +%F`
|
|
|
|
host=10.1.139.126
|
|
port=5432
|
|
username=rep
|
|
|
|
if [ $UID -ne `id -u $user` ];then
|
|
echo -e "\033[31;1mNot Manager of PostgreSQL! \033[0m"
|
|
exit 1
|
|
fi
|
|
|
|
# create base backup
|
|
echo -e "\033[33;1m---$today---\nBack up Now!\n---\033[0m"
|
|
if [ -f "$backup/$today/base" ];then
|
|
mkdir -p $backup/$today/base
|
|
fi
|
|
pg_basebackup -D $backup/$today/base -h $host -p $port -Ft -z -P -v -w -U $username
|
|
echo -e "\033[33;1m---\n---Finish---\033[0m"
|
|
|
|
# switch wal
|
|
psql postgres -c "checkpoint;"
|
|
psql postgres -c "select pg_switch_wal();"
|
|
|
|
# clean backup 7 days ago
|
|
rm -rf $backup/$aweekago |