<commit_before>#!/bin/bash
#
# backup vCenter's Postgres database
# copyright (c) 2014 Pivotal Labs
#
# License: unlicense http://unlicense.org/
#
if [ $# -ne 2 ]; then
    echo "Usage: $0 S3-bucket-name file-prefix"
    echo "e.g."
    echo "  $0 vcenter.cf.nono.com vcenter_bkup"
    exit 2
fi

S3_BUCKET_NAME=$1
SQL_BKUP_FILE=$2_$(date +%Y-%m-%d-%H:%M)

# source in EMB_DB_INSTANCE and EMB_DB_USER
. /etc/vmware-vpx/embedded_db.cfg

# exit early if backup files aleady exist
ls /tmp/$SQL_BKUP_FILE* > /dev/null 2>&1 && exit 2

# stop the vmware-vpxd for as briefly as possible
service vmware-vpxd stop > /dev/null 2>&1
/opt/vmware/vpostgres/1.0/bin/pg_dump $EMB_DB_INSTANCE -U $EMB_DB_USER -Fp -c > /tmp/$SQL_BKUP_FILE.sql
service vmware-vpxd start > /dev/null 2>&1

gzip /tmp/$SQL_BKUP_FILE.sql
if /usr/local/sbin/s3cmd-1.0.1/s3cmd put /tmp/$SQL_BKUP_FILE.sql.gz s3://$S3_BUCKET_NAME/ > /dev/null 2>&1; then
	:
else
	echo "S3 upload failed!"
	exit 3
fi<commit_msg>backup vCenter's Inventory Services database<commit_after>#!/bin/bash
#
# backup vCenter's Postgres 
# and inventory services databases
#
# copyright (c) 2014 Pivotal Labs
#
# License: unlicense http://unlicense.org/
#
# Successful operation is silent so as to not generate emails that
# clutter root's mailbox.

# Make sure you set your S3 bucket name!
S3_BUCKET_NAME=PLACEHOLDER_FOR_S3_BUCKET_NAME

DATE=$(date +%Y-%m-%d-%H:%M)
PG_BKUP_FILE=postgres_$DATE
IS_BKUP_FILE=inventory_services_$DATE

# source in EMB_DB_INSTANCE and EMB_DB_USER
. /etc/vmware-vpx/embedded_db.cfg

# exit early if backup files already exist
ls /tmp/$PG_BKUP_FILE* > /dev/null 2>&1 && exit 2

# stop the vmware-vpxd for as briefly as possible, backup up postgres
# http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2034505
service vmware-vpxd stop > /dev/null 2>&1
/opt/vmware/vpostgres/1.0/bin/pg_dump $EMB_DB_INSTANCE -U $EMB_DB_USER -Fp -c > /tmp/$PG_BKUP_FILE.sql
service vmware-vpxd start > /dev/null 2>&1

# stop the vmware-inventoryservice for as briefly as possible, backup up DB
# http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2062682
service vmware-inventoryservice stop
cd /usr/lib/vmware-vpx/inventoryservice/scripts/
./backup.sh -file /tmp/$IS_BKUP_FILE.DB
service vmware-inventoryservice start

# zip 'em up
gzip /tmp/$PG_BKUP_FILE.sql
gzip /tmp/$IS_BKUP_FILE.DB

# upload 'em
/usr/local/sbin/s3cmd-1.0.1/s3cmd put /tmp/$PG_BKUP_FILE.sql.gz s3://$S3_BUCKET_NAME/ > /dev/null 2>&1
rc_pg=$?
/usr/local/sbin/s3cmd-1.0.1/s3cmd put /tmp/$IS_BKUP_FILE.DB.gz  s3://$S3_BUCKET_NAME/ > /dev/null 2>&1
rc_is=$?

# are we cool?
if [ $rc_is -ne 0 ] || [ $rc_pg -ne 0 ]; then
   echo "S3 upload failed!"
   exit 3
fi
{'fraction_non_alphanumeric': 0.13689179375453886, 'fraction_numerical': 0.030501089324618737, 'mean_word_length': 4.168855534709193, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5587636', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1133, 'n_words': 254}