This commit is contained in:
6543 2019-03-05 17:40:59 +01:00
commit 8d2a28228f
5 changed files with 105 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/transport
/.Trash-*

0
2cp Normal file
View File

44
calc_md5.sh Normal file
View File

@ -0,0 +1,44 @@
#!/bin/bash

cd /mnt/export

#sort & del dublicates
sed -i '/^$/d' md5.txt
cat md5.txt | sort -k 2 | uniq > md5.txt_tmp
cat md5.txt_tmp > md5.txt

cat md5.txt_tmp | while read line; do
#get md5
md5=$(echo $line | cut -c -32)

#get path of file
file=$( echo $line | cut -c 34-)

#wenn datei existiert
if [ -f "$file" ]; then
# do nothing
echo > /dev/null
else
echo "rm $line"
sed -i "/$md5/d" md5.txt
fi

done

#search for new files
find /mnt/export/transport -type f | grep -v "/.Trash-" | sort | while read line; do
#save fiel path
result=$(grep "$line" md5.txt); [ -z "$result" ] && {
#wenn kein eintrag in liste...
echo "new $line"
md5sum "$line" >> md5.txt_add
}
done
[ -f md5.txt_add ] && {
cat md5.txt_add >> md5.txt
rm md5.txt_add
}

#sort & del dublicates
cat md5.txt | sort -k 2 | uniq > md5.txt_tmp
rm md5.txt && mv md5.txt_tmp md5.txt

58
cp_sh Normal file
View File

@ -0,0 +1,58 @@
#!/bin/bash
# @autor 6543@transport.de
# @date 2019-01-09
# @version 0.2

function free_disk() {
df "$1" | grep '/dev/' | sed -r -e "s/[\t\ ]+/ /g" | cut -d ' ' -f 4
}

md5="2cp"
aim="/mnt/export/transport"


md5_tmp=`mktemp`
freenow=0

cat "$md5" > "$md5_tmp"
cat "$md5_tmp" | while read line; do
file_orig="$(echo $line | cut -c 33- | sed -r -e "s/^[\ ]//g")"
file_size=$(du "$file_orig" | cut -f 1)
file_md5=$(echo $line | cut -c -32)
file_aim_dir=$(echo $file_orig | rev | cut -d '/' -f 2- | rev | sed 's/data\/Filme/mnt\/export\/transport/g')
file_aim=$(echo $file_orig | sed 's/data\/Filme/mnt\/export\/transport/g')

[ "$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
echo "$file_md5 $file_aim" >> /mnt/export/md5.txt
sed -i "/$file_md5/d" "$md5"
else
echo "Error: Hash mismatch: \"NEW:${file_md5_new} OLD:${file_md5}\" $file_aim"
sed -i "/$file_md5/d" "$md5"
fi

else
echo "To Big: $file_md5 $file_orig"
fi

else
echo "Error: Not Exist: $file_orig"
sed -i "/$file_md5/d" "$md5"
fi
done

rm "$md5_tmp"

1
md5.txt Normal file
View File

@ -0,0 +1 @@