-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix data wiping script according to recent changes (#261)
- Loading branch information
Showing
2 changed files
with
54 additions
and
56 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/bash | ||
|
||
echo "Usage: $0 mode(1:acct_table | 2:qos_table | 3:task_table | 4:user_table | 5:all | 6:acct_table+qos_table+user_table)" | ||
|
||
if [ "$#" -ne 1 ]; then | ||
echo "Parameter error: please input mode num!" | ||
exit 1 | ||
fi | ||
|
||
mode=$1 | ||
|
||
# Read info from configuration file | ||
conf_file=/etc/crane/database.yaml | ||
base_dir=/var/crane/ | ||
|
||
username=$(grep 'DbUser:' "$conf_file" | awk '{print $2}') | ||
password=$(grep 'DbPassword:' "$conf_file" | awk -F\" '{print $2}') | ||
host=$(grep 'DbHost:' "$conf_file" | awk '{print $2}') | ||
port=$(grep 'DbPort:' "$conf_file" | awk '{print $2}') | ||
dbname=$(grep 'DbName:' "$conf_file" | awk '{print $2}') | ||
embedded_db_path="$base_dir$(grep 'CraneCtldDbPath:' "$conf_file" | awk '{print $2}')" | ||
|
||
# Use mongosh to connect to MongoDB and wipe data | ||
function wipe_collection() { | ||
mongosh --username "$username" --password "$password" --host "$host" --port "$port" --authenticationDatabase admin <<EOF | ||
use $dbname | ||
db.$1.deleteMany({}) | ||
exit | ||
EOF | ||
} | ||
|
||
# Wipe data according to mode | ||
if [ "$mode" -eq 1 ] || [ "$mode" -eq 5 ] || [ "$mode" -eq 6 ]; then | ||
wipe_collection acct_table | ||
fi | ||
if [ "$mode" -eq 2 ] || [ "$mode" -eq 5 ] || [ "$mode" -eq 6 ]; then | ||
wipe_collection qos_table | ||
fi | ||
if [ "$mode" -eq 3 ] || [ "$mode" -eq 5 ]; then | ||
wipe_collection task_table | ||
|
||
# Get the directory and filename of the embedded database | ||
db_dir=$(dirname "$embedded_db_path") | ||
db_filename=$(basename "$embedded_db_path") | ||
|
||
# Remove the embedded database files | ||
if [ -d "$db_dir" ]; then | ||
echo "Removing files like $db_filename* in $db_dir ..." | ||
rm -f "$db_dir"/"$db_filename"* | ||
fi | ||
fi | ||
if [ "$mode" -eq 4 ] || [ "$mode" -eq 5 ] || [ "$mode" -eq 6 ]; then | ||
wipe_collection user_table | ||
fi |
This file was deleted.
Oops, something went wrong.