Zalohovanie sd karty obycajnym kopirovanim na inu sd kartu je super, ale ked je tych kariet viac, straca sa prehlad, je lepsie zalohovat na sietovy HDD.
Aj pre ine prakticke dovody hlavnu particiu na karte skratim pre zaciatok tak, aby nebola zbytocne velka, ja davam tak, aby som tam mal cca 3 GB volneho miesta. Posluzi graficky program gparted, karta nesmie byt mountnuta, takze v citacke.
Potom vytvorim na USB alebo CIFS (samba) disku adresar BACKUPS. Cela cesta v skripte je /media/hdd/BACKUPS. Pripadne pouzitie inej cesty vyzaduje upravu skriptu. Skript ulozim do adresara BACKUPS, ale moze byt aj inde.
zaloha_pi.bash
Kód: Vybrat vše
#!/bin/bash -x
# vytvorenie zalohy sd karty na sietovy alebo lokalny HDD
# Disk je uz mountnuty a obsahuje adresar BACKUPS
offset=`fdisk -l /dev/mmcblk0|perl -nae '$a= @F[1]*512;print $a if m/Linux/'`
count=`fdisk -l /dev/mmcblk0|perl -nae '$a= @F[2]+1 ;print $a if m/Linux/'`
date=`date "+%Y%m%d"`
skriptik=`hostname`_${offset}_${date}.sh
cesticka=`find /media/hdd -type d -name "BACKUPS"`
if [ ! -d "$cesticka" ]
then
echo !!!!!!!!! nic nebude, adresar BACKUPS nieje k dispozicii !!!!!
echo Vytvor adresar BACKUPS v ceste /media/hdd a skus zas !!!!
exit
fi
cesticka=${cesticka}/`hostname`/
if [ ! -d "${cesticka}" ]
then
mkdir ${cesticka}
fi
if [ ! -d "${cesticka}" ]
then
echo !!!!!!!!! nic nebude, ${cesticka} nieje k dispozicii !!!!!
exit
fi
ls -l ${cesticka}*.img
backup_name=${cesticka}`hostname`_${offset}_${date}.img
while true; do
read -p "Naozaj zalohovat do ${backup_name} bytes: $(echo $count*512|bc) ? Potrva asi pol hodky! [y/n] " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Odpovedz y alebo n";;
esac
done
echo ide sa dalej, trpezlivost! ${backup_name}
zaciatok=`echo zaciatok: $(date) count: $count`
echo $zaciatok
#dd bs=512 count=14825472 if=/dev/mmcblk0 of=/media/hdd/BACKUPS/PIPC4/PiPc4_20200407.img
dd bs=512 count=$count if=/dev/mmcblk0 of=${backup_name}
#dd bs=512 count=$count if=/dev/mmcblk0 of=${backup_name} status=progress
echo Hotovo:`date`
ls -l ${cesticka}/`hostname`_${offset}_${date}.img
koniec=`echo Hotovo: $(date)`
echo \#!/bin/bash >${cesticka}$skriptik
echo \# $zaciatok >>${cesticka}$skriptik
echo \# $koniec >>${cesticka}$skriptik
echo mount -o loop,offset=$offset ${cesticka}`hostname`_${offset}_${date}.img /media/tmp>>${cesticka}$skriptik
chmod 755 ${cesticka}$skriptik
echo pre mount obrazu stpust: ${cesticka}$skriptik
echo IMG file kopirovat na karticku win32imager-om alebo inym podobnym programom
Pocas zalohovanie minimalizujeme aktivity na zalohovanom stroji.
Okrem zalohy, ktoru je mozne potom nakopirovat na SD kartu (WinImager, Etcher, Raspbery pi Imager), skript vytvori aj dalsi skript na mountnutie img priamo v sbc. Potom sa zaloha da aktualizovat podla potreby prikazom rsync. Napriklad takto
rsync.bash
Kód: Vybrat vše
#!/bin/bash -x
date
diff /etc/hostname /media/tmp/etc/hostname
rc=$?
if [[ $rc != 0 ]]; then
echo "nic nebude, zaloha nesedi"
exit $rc
else
echo je to ok
fi
touch rsync.log
echo `cat /etc/hostname` Start `date` >>rsync.log
rsync --progress -qaWHAXS --exclude={"/dev/*","/proc/*","/var/log/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / /media/tmp
date
echo `cat /etc/hostname` Finish `date` >>rsync.log