-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbulk_load_file.sh
50 lines (40 loc) · 1.33 KB
/
bulk_load_file.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
#!/bin/bash
# Base directory where article folders are stored inside the container
BASE_DIR="/etc/fdfs_buffer"
# FastDFS client configuration file
FDFS_CLIENT_CONF="/etc/fdfs/client.conf"
# Base URL for accessing files from FastDFS storage
STORAGE_BASE_URL="http://0.0.0.0:9090"
# Output file for mapping results
MAPPING_FILE="/etc/fdfs_buffer/mapping_results.txt"
# Function to upload a file and record its mapping
upload_file() {
local file_path=$1
local file_name=$(basename "$file_path")
local upload_info=$(fdfs_upload_file $FDFS_CLIENT_CONF "$file_path")
local result=$?
if [ $result -eq 0 ]; then
local file_url="${STORAGE_BASE_URL}/${upload_info}"
echo "$file_name --> $file_url" >> $MAPPING_FILE
else
echo "Error uploading file: $file_name" >> $MAPPING_FILE
fi
}
# Check if the base directory exists
if [ ! -d "$BASE_DIR" ]; then
echo "Directory $BASE_DIR does not exist."
exit 1
fi
# Create or clear the mapping file
> $MAPPING_FILE
# Iterate over each article folder and upload its files
for article_dir in "$BASE_DIR"/article*/; do
if [ -d "$article_dir" ]; then
for file in "$article_dir"/*; do
if [ -f "$file" ]; then
upload_file "$file"
fi
done
fi
done
echo "Bulk upload complete. Mapping stored in $MAPPING_FILE"