Last active
August 29, 2015 14:07
-
-
Save hungpk/79535f10db195871ffb7 to your computer and use it in GitHub Desktop.
Collect PostgreSQL stat using pgcluu_collectd and put it to S3
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/sh | |
HOST=$1 | |
BASE_DIR=$2 | |
S3BUCKET=<s3-bucket> | |
NOW=`date +"%Y-%m-%d"` | |
PREFIX=pgcluu | |
DATA_DIR=$BASE_DIR/$PREFIX-$NOW | |
#kill current process | |
pgcluu_collectd -k -f $BASE_DIR/current/pg_cluu_collectd.pid | |
#backup current and put to S3 | |
tar chzf $DATA_DIR.tgz $BASE_DIR/current | |
s3cmd put $DATA_DIR.tgz $S3BUCKET | |
rm $DATA_DIR.tgz | |
# | |
mkdir -p $DATA_DIR | |
rm $BASE_DIR/current ; ln -s $DATA_DIR $BASE_DIR/current | |
pgcluu_collectd -D -S -h $HOST -f $DATA_DIR/pg_cluu_collectd.pid -p 5432 -U postgres --pgbouncer-args="-p 6432" $DATA_DIR | |
#remove old folders, keep last 3 one | |
ls -t1 $BASE_DIR/$PREFIX* |tail -n +4 | xargs rm -rf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment