2. redigeri: sudo /etc/fstab
3. ... lisa rida: //999.888.555.1/NAS/backup /mnt/backup cifs user,guest,uid=1000,iocharset=utf8 0 0
4. testi: sudo mount -a
5. lae alla: sudo wget https://github.com/kallsbo/BASH-RaspberryPI-System-Backup/raw/master/system_backup.sh
6. ... muuda rida # Perform backup# dd if=/dev/xxxxxx ... kui op susteem ei ole SD kaardil
7. tee käivitatavaks: sudo chmod +x system_backup.sh
8. lisa crontabi: sudo crontab -e
9. ... rida: 0 3 * * * /mnt/backup/system_backup.sh
system_backup.sh
#!/bin/bash
#
# Automate Raspberry Pi Backups
#
# Kristofer Källsbo 2017 www.hackviking.com
#
# Usage: system_backup.sh {path} {days of retention}
#
# Below you can set the default values if no command line args are sent.
# The script will name the backup files {$HOSTNAME}.{YYYYmmdd}.img
# When the script deletes backups older then the specified retention
# it will only delete files with it's own $HOSTNAME.
#
# Declare vars and set standard values
backup_path=/mnt/backup
retention_days=3
# Check that we are root!
if [[ ! $(whoami) =~ "root" ]]; then
echo ""
echo "**********************************"
echo "*** This needs to run as root! ***"
echo "**********************************"
echo ""
exit
fi
# Check to see if we got command line args
if [ ! -z $1 ]; then
backup_path=$1
fi
if [ ! -z $2 ]; then
retention_days=$2
fi
# Create trigger to force file system consistency check if image is restored
touch /boot/forcefsck
# Perform backup
dd if=/dev/mmcblk0 of=$backup_path/$HOSTNAME.$(date +%Y%m%d).img bs=1M
# Remove fsck trigger
rm /boot/forcefsck
# Delete old backups
find $backup_path/$HOSTNAME.*.img -mtime +$retention_days -type f -delete