Skip to content

Instantly share code, notes, and snippets.

@TheCodeDestroyer
Created April 10, 2016 16:03
Show Gist options
  • Select an option

  • Save TheCodeDestroyer/3a763de04980331a650a414ffbadb23c to your computer and use it in GitHub Desktop.

Select an option

Save TheCodeDestroyer/3a763de04980331a650a414ffbadb23c to your computer and use it in GitHub Desktop.
Raspberry Pi backup script (shell)
#!/bin/bash
echo "Specify block device name:"
read BLOCK_DEVICE_NAME
echo "Is this the correct device: /dev/$BLOCK_DEVICE_NAME (Y/n)"
read ANSWER
if [ "$ANSWER" == "n" ]; then
exit 0
fi
IMG_SIZE="$(sudo blockdev --getsize64 /dev/$BLOCK_DEVICE_NAME)"
echo "Type of backup: (GZIP/img)"
read BACKUP_TYPE
if [ "$BACKUP_TYPE" == "img" ]
then
sudo dd bs=4M if=/dev/$BLOCK_DEVICE_NAME | pv --rate --bytes --progress --size $IMG_SIZE --eta | dd of=raspbian.img
else
sudo dd bs=4M if=/dev/$BLOCK_DEVICE_NAME | pv --rate --bytes --progress --size $IMG_SIZE --eta | gzip > rasbian.img.gz
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment