Hallo zusammen.
Ich brauche mal eure Hilfe bei einem Bash Script. Ich habe noch keine Shell Scripte geschrieben und komme damit noch nicht so ganz klar.
Was soll das Scipt machen?
Ich möchte ein automatisches Backupscript schreiben. Es soll erst einmal schauen ob der USB Stick gemounted ist. Dann per dd ein Backup der SD Karte machen. War das erfolgreich, dann mit pishrink das Image auf eine notwendige Größe verkleinern. Und wenn das auch erfolgreich war, dann das das verkleinerte Image noch einmal auf einen anderen USB Stick kopieren (doppeltes Backup).
Was habe ich bis jetzt?
Testen ob die Sticks gemounted sind.
dd mit test ob erfolgreich.
Was brauche ich noch?
Check ob PIshrink erfolgreich war.
Optimierungen...
Das Bash Script, bis jetzt:
#!/bin/bash
date=$(date +%Y%m%d)
input_path=""
output_path="/media/speicherstick"
output_file="rpi_${date}.img"
backup_stick="media/backupstick"
echo $output_file
#check if the usb stick is mounted
if [ $(mount | grep -c $output_path) != 1 ]
then
echo "${output_path} is not mounted."
exit 91
fi
# write the image file
sudo dd if="$input_path" of="${output_path}/${output_file}"
ret=$?
if [ $ret gt 0 ]; then
echo "Writing image file failed ...."
exit 92
fi
# shrink the image file
sudo pishrink.sh ${outputpath}/${output_file} ${output_path}/shrink_${output_file}
# delete big image file
sudo rm ${outputpath}/${output_file}
# check if the backup stick is mounted
if [ $[mount |grep -c $backup_stick) != 1 ]
then
echo "${backup_stick} is not mounted..."
exit 93
fi
sudo cp ${output_path}/shrink_${output_file} $backup_stick
echo "done..."
Alles anzeigen
Kann mir jemand sagen wie ich prüfe ob PIshrink erfolgreich durchgelaufen ist?
Und kann man das Script noch optimieren? Ich habe ein ähnliches Script gefunden das diverse Services vorher gestoppt hat. Z.B. Apache, Cron, etc. Ist das zu empfehlen? Auch habe ich teilweise Anleitungen gesehen die dd mit noch weiteren Parametern füttern. Sind diese notwendig und wozu sind sie (z.B. bs=1M conv=sync,noerror iflag=fullblock)?
Sonstige Anmerkungen, Verbesserungsvorschläge?
Danke.