Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # attempt at a script to backup 3ds SD that can also install on new one
- # V2 ! Now catches to block you from writing/reading on mounted devices! No more overwriting /dev/sda
- # by imanoob (on irc)/LiquidFenrir (literally everywhere else)
- # I can not be held responsible for whatever happens to your data when using this script!
- PATHTOBACKUPS="/root/sdbackups/"
- echo "This script uses '~/sdbackups/' as the directory to store the backups of the SD, as an .iso file named with a timestamp."
- echo "WANRNING: The generated .iso will be the size of the entire SD. Make sure you have enough free space!"
- echo "What do you want to do? 'backup' or 'install' ?"
- while read action
- do
- if [ "$action" == "backup" ] || [ "$action" == "install" ]; then
- break
- else
- echo "This is not a right input. Please enter 'backup' or 'install' !"
- fi
- done
- temp=$(df | tr "" "\n")
- devices=()
- for x in $temp
- do
- if [[ "$x" =~ .*dev/*. ]]; then
- devices+=("$x")
- fi
- done
- echo "Use 'fdisk -l' to know connected drives and 'df' to know mounted drives. Do not use partitions."
- echo "ex: use /dev/sdb instead of /dev/sdb1"
- echo "ex: use /dev/mmcblk0 instead of /dev/mmcblk0p1"
- echo "What is the location of the SD ?"
- while read name
- do
- state="good"
- if [ -e "$name" ]; then
- for x in ${devices[@]}
- do
- if [[ "$x" =~ "$name" ]]; then
- echo "This device is mounted! Please unmount it or use an other one."
- state="error"
- break
- fi
- done
- else
- echo "This device does not exist. Please use an other one."
- state="error"
- fi
- if [ "$state" == "error" ]; then
- echo "What is the location of the SD?"
- else
- break
- fi
- done
- echo "Press any key to start the $action. Press Ctrl+C to cancel."
- read
- if [ "$action" == "backup" ]; then
- DATE=$(date +%Y-%m-%d-%H%M)
- fullpath="$PATHTOBACKUPS$DATE.iso"
- echo "Writing data from '$name' to '$fullpath'. Please wait until completion. Closure may result in corruption of drives."
- touch "$fullpath"
- dd if="$name" of="$fullpath" bs=2k
- echo "Done!"
- elif [ "$action" == "install" ]; then
- echo "Which backup do you want to use? (template: YYYY-MM-DD-HHmm do not add the .iso at the end, it will do it automatically.)"
- read backup
- fullpath="$PATHTOBACKUPS$backup.iso"
- echo "Writing data from '$fullpath' to '$name'. Please wait until completion. Closure may result in corruption of drives."
- dd if="$fullpath" of="$name" bs=2k
- echo "Done!"
- else
- echo "An error occured! Please try again."
- fi
Advertisement
Add Comment
Please, Sign In to add comment