-
Notifications
You must be signed in to change notification settings - Fork 0
/
zipAndTransfer.sh
60 lines (48 loc) · 1.92 KB
/
zipAndTransfer.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
#!/bin/bash
# Variables
directoryPath="/path/to/directory"
logFilePath="/path/to/log.txt"
fileNameChangeIndex="/path/to/fileNameChangeIndex.txt"
maxFilesPerZip=10000
sanitizeFileName="Y"
completedFoldersList="/path/to/completedFoldersList.txt"
completedFoldersFilePath="/path/to/completedFoldersFilePath.txt"
failedFoldersFilePath="/path/to/failedFoldersFilePath.txt"
# Function to process directories
zipAndTransfer() {
local dirPath="$1"
echo "Processing directory: $dirPath" | tee -a "$logFilePath"
# Check if the folder has already been processed
if grep -Fxq "$dirPath" "$completedFoldersList"; then
echo "....Skipping already processed folder...."
return
fi
# Sanitize and zip files in the directory
if [ "$sanitizeFileName" = "Y" ]; then
echo "Sanitizing the file names and zipping..."
# Create a temporary directory for sanitized files
tempDir=$(mktemp -d)
# Find all files and sanitize names
find "$dirPath" -type f | while read -r file; do
filename=$(basename -- "$file")
sanitizedFileName=$(echo "$filename" | sed 's/[^a-zA-Z0-9.-]/_/g')
cp "$file" "$tempDir/$sanitizedFileName"
echo "$file -> $tempDir/$sanitizedFileName" >> "$fileNameChangeIndex"
done
# Zip the sanitized files
zipFilePath="$dirPath.zip"
(cd "$tempDir" && zip -r "$zipFilePath" .)
# Transfer the zip file to AWS Snowball Edge
awsKey="wbtx-archived-scientific-data/${zipFilePath#*/}" # Adjust path as needed
aws s3 cp "$zipFilePath" "s3://$awsKey" --endpoint-url "http://192.168.16.67:8080"
# Cleanup
rm -rf "$tempDir"
rm -f "$zipFilePath"
fi
# Check for subdirectories and process them
find "$dirPath" -mindepth 1 -type d | while read -r subdir; do
zipAndTransfer "$subdir"
done
}
# Start processing
zipAndTransfer "$directoryPath"