Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Gen 465 backup timescaledb #132

Open
wants to merge 2 commits into
base: test
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions deployments/scripts/backup_timescale.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# This script is run on daily basis as a cronjob
# 0 0 * * * /bin/bash /data/scripts/backup_timescale.sh > /dev/null

STR_DATE="$(date '+%Y_%m_%d')"
DIR_TIMESCALEDB="/data/backup/timescaledb"
FILE_BACKUP="$DIR_TIMESCALEDB/timescaledb_dump_$STR_DATE.sql"
CLEAN_CYCLE=5

# timescaledb info
PRODUCTION_DB_USER="$(cat /data/secrets/production/pss_db_user)"
PRODUCTION_DB_PASSWORD="$(cat /data/secrets/production/pss_db_password)"
PRODUCTION_DB_HOST="incrudibles-production.db.pdl.cmu.edu"
PRODUCTION_DB_PORT="32003"
PRODUCTION_DB_NAME="postgresql://$PRODUCTION_DB_USER:$PRODUCTION_DB_PASSWORD@$PRODUCTION_DB_HOST:$PRODUCTION_DB_PORT/pss_database?sslmode=disable"

# install pg_dump if not installed
which pg_dump > /dev/null
if [ $? -ne 0 ]; then
sudo /usr/bin/apt update -y
sudo /usr/bin/apt install postgresql-client
fi

# create the timescaledb backup dir if not exists
/bin/mkdir $DIR_TIMESCALEDB

# dump the timescaledb
/usr/bin/pg_dump -d $PRODUCTION_DB_NAME -f $FILE_BACKUP

# delete redundant outdated backups
/usr/bin/find $DIR_TIMESCALEDB/* -mtime +$CLEAN_CYCLE -delete
18 changes: 18 additions & 0 deletions deployments/scripts/create_nfs_mount.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
REMOTE_DIR="basket.pdl.local.cmu.edu:/cmudb-testingteam-backup"
LOCAL_DIR="/data/backup"

# install nfs-common if not installed
which mount > /dev/null
if [ $? -ne 0 ]; then
sudo apt update -y
sudo apt install nfs-common
fi

# create the local backup dir if not exists
mkdir -p $LOCAL_DIR

# mount the local backup dir to remote nfs if not mounted
if [ "$(stat -f -L -c %T $LOCAL_DIR)" != "nfs" ]; then
mount $REMOTE_DIR $LOCAL_DIR
fi