Daten automatisch auf mehrere Medien verteilen
Posted: 09. Oct 2005 2:38
Ich suche ein Programm um mehr als 20GB Daten automatisch und nicht komprimiert auf mehrere Medien zu brennen
Pro-Linux Diskussions- und Hilfeforum
https://www.pro-linux.de/forum/
Code: Select all
#!/bin/bash
function save_dir(){
dir=$1
file_list_prefix=$2
todo_list_prefix=$3
MED_SIZE=$4
index=$5
list_size=0
index=$[$index+1]
matching_element_ignored=0
file_list="$file_list_prefix"."$index"
todo_list="$todo_list_prefix"."$index"
next_todo_list="$todo_list".next
ls -A $dir >> $todo_list
matching_element_ignored=create_list $file_list $todo_list $next_todo_list $MED_SIZE
while [ "$matching_element_ignored" -eq 1 ]; do
$matching_element_ignored=0
mv "$next_todo_list" "$todo_list"
# Auf der todo-Liste befinden sich noch Elemente,
# welche klein genug sind, um gesichert zu werden
index=$[$index+1]
file_list="$file_list_prefix"."$index"
matching_element_ignored=create_list $file_list $todo_list $next_todo_list $MED_SIZE
done
# Alles was jetzt noch in todo_list steht, sind Verzeichnisse,
# welche zu gross sind, um sie sofort zu sichern
# Diese werden jetzt auch noch gesichert:
rm $next_todo_list
rm $todo_list
for subdir in $(cat $todo_list); do
save_dir $subdir, $file_list_prefix $todo_list_prefix $MED_SIZE $index
done
}
function create_list(){
file_list=$1
todo_list=$2
next_todo_list=$3
MED_SIZE=$4
# Fuer jede Datei und jedes Verzeichnis
for element in $(cat $todo_list); do
if_file=0
cd $element || is_file=1
if [ "$is_file" -eq 0 ]; then
cd $dir
fi
# Bestimme die Groesse des Elements
element_size = $(du -s $element | awk ' { print $1 } ')
if [ $[$list_size + $element_size] -gt $MED_SIZE ]; then
# Fuege es zur todo-Liste hinzu, wenn es
# fuer die aktuelle Liste zu gross ist
# Aber nur dann, wenn es keine Datei ist,
# welche groesser als MED_SIZE ist
if [ $is_file -eq 0 -o $element_size -le $MED_SIZE ]; then
echo "$dir"/"$element" >> $next_todo_list
else
echo "file $element is too large to be saved!"
fi
# und notiere, wenn es insgesamt klein genug ist,
# um gesichert zu werden.
matching_element_ignored=1
else
# Ansonsten fuege es zur aktuellen Liste hinzu
$list_size = $[$list_size + $element_size]
echo "$dir"/"$element" >> $file_list
fi
done
return $matching_element_ignored
}
# Elemente werden mit Newline getrennt
IFS="
"
# Gibt die Groesse der Sicherunsmedien in Byte an
MED_SIZE=700*1024*1024 # 700 MB
# Temporaeres Verzeichnis
TMP_DIR=/tmp
# Zu sicherndes Verzeichnis
SAVE_DIR=/usr/ports/distfiles
# Optionen fuer mkisofs
MKISOFS_OPT="-r"
# Optionen fuer cdrecord
CDRECORD_OPT="-dev=/dev/cdrw speed=8 -eject"
date=$(date +%s)
file_list_prefix="$TMP_DIR"/backup."$date".list
todo_list_prefix="$TMP_DIR"/backup."$date".todo
save_dir $SAVE_DIR $file_list_prefix $todo_list_prefix $MED_SIZE 0
exit 0
# Erzeuge die Medien
for file in $(ls "$file_list_prefix"*); do
echo "I'm going to write all files in $file now."
echo ""
echo Please insert a medium and press any key
read
cat file | xargs mkisofs $MKISOFS_OPT | cdrecord $CDRECORD_OPT
done
exit 0