Skip to content

Instantly share code, notes, and snippets.

@rosenhouse
Created May 19, 2014 23:57
Show Gist options
  • Save rosenhouse/d60c01508e8572fead70 to your computer and use it in GitHub Desktop.
Save rosenhouse/d60c01508e8572fead70 to your computer and use it in GitHub Desktop.
MacOS SD card backup and restore
#!/bin/bash -e
# simple script to automate backup of SD cards to a file on disk
# only works on Mac OS at this time.
if [ -z "$1" ]; then
echo "Specify an img name to save to"
exit
fi
echo Will output data to:
echo $1
diskUtil list
echo "Enter disk number, i.e. the X in /dev/diskX"
read n
echo "Enter the number of 1M blocks"
read count
echo "unmounting"
diskUtil unmountDisk /dev/disk$n
echo "copying (this will take a while)"
dd bs=1m if=/dev/rdisk$n of=$1 count=$count
echo "ejecting"
sleep 2
diskUtil eject /dev/disk$n
echo "done"
#!/bin/bash -e
# simple script to automate flashing an img file to an SD card
# only works on Mac OS at this time.
if [ -z "$1" ]; then
echo "Specify an img file name on the command line"
exit
fi
echo Will use iso:
ls $1
diskUtil list
echo "Enter disk number, i.e. the X in /dev/diskX"
read n
echo "unmounting"
diskUtil unmountDisk /dev/disk$n
echo "copying (this will take a while)"
dd bs=1m if=$1 of=/dev/rdisk$n
echo "ejecting"
sleep 2
diskUtil eject /dev/disk$n
echo "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment