2019-03-05 16:40:59 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# @autor 6543@transport.de
|
|
|
|
# @date 2019-01-09
|
|
|
|
# @version 0.2
|
|
|
|
|
|
|
|
function free_disk() {
|
2019-09-04 13:18:41 +00:00
|
|
|
df "$1" | tail -n1 | sed -r -e "s/[\t\ ]+/ /g" | cut -d ' ' -f 4
|
2019-03-05 16:40:59 +00:00
|
|
|
}
|
|
|
|
|
2019-09-10 23:18:10 +00:00
|
|
|
md5="2cp.md5"
|
2019-03-05 16:40:59 +00:00
|
|
|
aim="/mnt/export/transport"
|
2019-09-10 23:19:04 +00:00
|
|
|
source="/data/Filme"
|
2019-03-05 16:40:59 +00:00
|
|
|
|
2019-09-11 00:15:32 +00:00
|
|
|
## prepare
|
|
|
|
aim="$(echo $aim | sed 's/\/$//g')"
|
|
|
|
source="$(echo $source | sed 's/\/$//g')"
|
2019-03-05 16:40:59 +00:00
|
|
|
|
|
|
|
md5_tmp=`mktemp`
|
|
|
|
cat "$md5" > "$md5_tmp"
|
2019-09-04 13:52:30 +00:00
|
|
|
sed -i '/^$/d' "$md5_tmp"
|
2019-09-11 00:15:32 +00:00
|
|
|
sed -i "s/${source//'/'/'\/'}//g" "$md5_tmp" #from absolut to relative paths
|
|
|
|
|
|
|
|
freenow=0
|
|
|
|
|
|
|
|
|
|
|
|
## start prosessing
|
2019-03-05 16:40:59 +00:00
|
|
|
cat "$md5_tmp" | while read line; do
|
2019-09-11 00:15:32 +00:00
|
|
|
file="$(echo $line | cut -c 33- | sed -r -e "s/^[\ ]//g")"
|
|
|
|
file_orig="${source}${file}"
|
2019-03-05 16:40:59 +00:00
|
|
|
file_size=$(du "$file_orig" | cut -f 1)
|
|
|
|
file_md5=$(echo $line | cut -c -32)
|
2019-09-11 00:15:32 +00:00
|
|
|
file_aim="${aim}${file}"
|
|
|
|
file_aim_dir=$(echo $file_aim | rev | cut -d '/' -f 2- | rev)
|
2019-03-05 16:40:59 +00:00
|
|
|
|
|
|
|
[ "$file_orig" == "$file_aim" ] && { echo Script ERROR; exit 255; }
|
|
|
|
|
|
|
|
freenow=$(free_disk "$aim")
|
|
|
|
#add puffer
|
|
|
|
freenow=$((freenow-10240))
|
|
|
|
|
|
|
|
if [ -f "$file_orig" ]; then
|
|
|
|
|
|
|
|
if [ "$freenow" -ge "$file_size" ]; then
|
|
|
|
|
|
|
|
mkdir -p "$file_aim_dir"
|
|
|
|
[ -f "$file_aim" ] && rm "$file_aim"
|
|
|
|
|
|
|
|
file_md5_new=$(cat "$file_orig" | tee "$file_aim" | md5sum | cut -c -32)
|
|
|
|
|
|
|
|
if [ "${file_md5_new}" == "${file_md5}" ]; then
|
2019-09-11 00:15:32 +00:00
|
|
|
echo "$file_md5 $file_aim" | tee -a "${md5}.sucess-log"
|
2019-03-05 16:40:59 +00:00
|
|
|
sed -i "/$file_md5/d" "$md5"
|
|
|
|
else
|
2019-09-04 16:50:14 +00:00
|
|
|
echo "Error: Hash mismatch: \"NEW:${file_md5_new} OLD:${file_md5}\" $file_aim" | tee -a "${md5}.error-log"
|
2019-03-05 16:40:59 +00:00
|
|
|
sed -i "/$file_md5/d" "$md5"
|
|
|
|
fi
|
|
|
|
|
|
|
|
else
|
2019-09-04 16:50:14 +00:00
|
|
|
echo "To Big: $file_md5 $file_orig" | tee -a "${md5}.error-log"
|
2019-03-05 16:40:59 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
else
|
2019-09-04 16:50:14 +00:00
|
|
|
echo "Error: Not Exist: $file_orig" | tee -a "${md5}.error-log"
|
2019-03-05 16:40:59 +00:00
|
|
|
sed -i "/$file_md5/d" "$md5"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
rm "$md5_tmp"
|