Created
April 13, 2017 03:22
-
-
Save diggzhang/d01b98b26687a84ea8996730bad7b630 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env bash | |
DB_HOST="10.8.2.97" && \ | |
DB_NAME_EVENTS="eventsV4" && \ | |
DB_COLLECITON_NAME="eventV4" && \ | |
YEAR=$(date -d -1day '+%Y') && \ | |
MONTH=$(date -d -1day '+%m') && \ | |
DAY=$(date -d -1day '+%d') && \ | |
LOGFILE=/tmp/renameCollectionEventV4EveryMonth_"$YEAR$MONTH".log && \ | |
echo "[*] " > "$LOGFILE" | |
echolog() | |
( | |
echo "[*] $1" | |
echo "[*] $1" >> "$LOGFILE" | |
) | |
echolog "code start $(date)" | |
echolog "******************************************" | |
echolog "* rename eventv4 every month first day *" | |
echolog "* @diggzhang *" | |
echolog "******************************************" | |
echolog "$DB_HOST: $DB_NAME_EVENTS: $DB_COLLECITON_NAME: $YEAR$MONTH$DAY" | |
echolog "Part.1 start-----------------------------------------*" | |
echolog "Rename collection" | |
echo "db.$DB_COLLECITON_NAME.renameCollection(\"$DB_COLLECITON_NAME$YEAR$MONTH$DAY\")" > "mongoRenameEvents$YEAR$MONTH$DAY".js && \ | |
./mongo --host $DB_HOST $DB_NAME_EVENTS ./"mongoRenameEvents$YEAR$MONTH$DAY".js >> "$LOGFILE" | |
echolog "Part.1 end-------------------------------------------*" | |
echolog "code end $(date)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment