Skip to content

Instantly share code, notes, and snippets.

@maciekish
Last active September 25, 2020 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maciekish/dc1f9372916eacf06efe10aa6e9469cd to your computer and use it in GitHub Desktop.
Save maciekish/dc1f9372916eacf06efe10aa6e9469cd to your computer and use it in GitHub Desktop.
Backup Pi SD Card to Samba
#!/bin/bash
#Usage bash <(curl -Ls https://gist.githubusercontent.com/maciekish/dc1f9372916eacf06efe10aa6e9469cd/raw)
if [ `whoami` != 'root' ]
then
echo "You must be root to do this."
exit
fi
if [ -z "$1" ]
then
echo "Please specify block device to backup as first argument. Usually this is /dev/mmcblk0 on Raspbian."
exit
fi
umount /mnt/backup
mkdir /mnt/backup
mount -t cifs -o user=maciekish //10.0.1.0/backup /mnt/backup
size=$(blockdev --getsize64 $1)
echo "Backing up $1 ($size bytes)"
dd bs=4M if=$1 | pv --size $size | gzip > /mnt/backup/sdcard.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment