Skip to content

Commit

Permalink
fix: Fix data wiping script according to recent changes (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nativu5 authored May 21, 2024
1 parent 305b9f1 commit 5683e81
Showing 2 changed files with 54 additions and 56 deletions.
54 changes: 54 additions & 0 deletions scripts/WipeData.sh
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
56 changes: 0 additions & 56 deletions scripts/wipe_data.sh

This file was deleted.

0 comments on commit 5683e81

Please sign in to comment.