-
Notifications
You must be signed in to change notification settings - Fork 25
/
buildArchivePackages.sh
73 lines (59 loc) · 2.04 KB
/
buildArchivePackages.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
# Default prefix for databases
DB_PREFIX="hdb_"
# Path to the configuration file
CONFIG_FILE="../heuristConfigIni.php"
# Path to the PHP script relative to the shell script
PHP_SCRIPT="./export/dbbackup/buildArchivePackagesCMD.php"
# Usage instructions
usage() {
echo "Usage: $0 [ALL | dbname1,dbname2,...]"
echo "Processes databases with the specified prefix. Default prefix is '$DB_PREFIX'."
exit 1
}
# Check if arguments are provided
if [ "$#" -ne 1 ]; then
usage
fi
# Get the list of databases or "ALL"
DB_LIST=$1
# Check if the configuration file exists
if [ ! -f "$CONFIG_FILE" ]; then
echo "Error: Configuration file not found: $CONFIG_FILE"
exit 1
fi
# Extract MySQL credentials from the configuration file
DB_HOST=$(grep -Po "(?<=\$dbHost = ')[^']*" "$CONFIG_FILE")
DB_USER=$(grep -Po "(?<=\$dbAdminUsername = ')[^']*" "$CONFIG_FILE")
DB_PASS=$(grep -Po "(?<=\$dbAdminPassword = ')[^']*" "$CONFIG_FILE")
# If dbHost is blank, use localhost
DB_HOST=${DB_HOST:-"localhost"}
# Verify the PHP script exists
if [ ! -f "$PHP_SCRIPT" ]; then
echo "Error: PHP script not found: $PHP_SCRIPT"
exit 1
fi
# Fetch all databases with the given prefix if ALL is specified
if [ "$DB_LIST" == "ALL" ]; then
DB_LIST=$(mysql -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASS" -e "SHOW DATABASES;" | grep "^$DB_PREFIX" | sed "s/^$DB_PREFIX//")
if [ -z "$DB_LIST" ]; then
echo "No databases found with prefix '$DB_PREFIX'."
exit 1
fi
else
# Split the comma-separated list into individual database names
IFS=',' read -r -a DB_ARRAY <<< "$DB_LIST"
DB_LIST="${DB_ARRAY[@]}"
fi
# Loop through the databases and call the PHP script for each
for DB in $DB_LIST; do
FULL_DB_NAME="${DB_PREFIX}${DB}"
echo "Processing database: $FULL_DB_NAME"
# Call the PHP script with the appropriate arguments -nosql -notsv -nofiles -nodocs
php "$PHP_SCRIPT" -- -db="$DB"
if [ $? -ne 0 ]; then
echo "Error: Failed to process database $FULL_DB_NAME."
exit 1
fi
done
echo "Processing complete."