LiquidFenrir

3ds SD backup/install V2

Jan 31st, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.51 KB | None | 0 0
  1. #!/bin/bash
  2. # attempt at a script to backup 3ds SD that can also install on new one
  3. # V2 ! Now catches to block you from writing/reading on mounted devices! No more overwriting /dev/sda
  4. # by imanoob (on irc)/LiquidFenrir (literally everywhere else)
  5. # I can not be held responsible for whatever happens to your data when using this script!
  6.  
  7. PATHTOBACKUPS="/root/sdbackups/"
  8.  
  9. echo "This script uses '~/sdbackups/' as the directory to store the backups of the SD, as an .iso file named with a timestamp."
  10. echo "WANRNING: The generated .iso will be the size of the entire SD. Make sure you have enough free space!"
  11. echo "What do you want to do? 'backup' or 'install' ?"
  12. while read action
  13. do
  14.     if [ "$action" == "backup" ] || [ "$action" == "install" ]; then
  15.     break
  16.     else
  17.     echo "This is not a right input. Please enter 'backup' or 'install' !"
  18.     fi
  19. done
  20. temp=$(df | tr "" "\n")
  21. devices=()
  22. for x in $temp
  23. do
  24.     if [[ "$x" =~ .*dev/*. ]]; then
  25.     devices+=("$x")
  26.     fi
  27. done
  28. echo "Use 'fdisk -l' to know connected drives and 'df' to know mounted drives. Do not use partitions."
  29. echo "ex: use /dev/sdb instead of /dev/sdb1"
  30. echo "ex: use /dev/mmcblk0 instead of /dev/mmcblk0p1"
  31. echo "What is the location of the SD ?"
  32. while read name
  33. do
  34.     state="good"
  35.     if [ -e "$name" ]; then
  36.     for x in ${devices[@]}
  37.     do
  38.         if [[ "$x" =~ "$name" ]]; then
  39.         echo "This device is mounted! Please unmount it or use an other one."
  40.         state="error"
  41.         break
  42.         fi
  43.     done
  44.     else
  45.     echo "This device does not exist. Please use an other one."
  46.     state="error"
  47.     fi
  48.     if [ "$state" == "error" ]; then
  49.     echo "What is the location of the SD?"
  50.     else
  51.     break
  52.     fi
  53. done
  54. echo "Press any key to start the $action. Press Ctrl+C to cancel."
  55. read
  56. if [ "$action" == "backup" ]; then
  57.     DATE=$(date +%Y-%m-%d-%H%M)
  58.     fullpath="$PATHTOBACKUPS$DATE.iso"
  59.     echo "Writing data from '$name' to '$fullpath'. Please wait until completion. Closure may result in corruption of drives."
  60.     touch "$fullpath"
  61.     dd if="$name" of="$fullpath" bs=2k
  62.     echo "Done!"
  63. elif [ "$action" == "install" ]; then
  64.     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.)"
  65.     read backup
  66.     fullpath="$PATHTOBACKUPS$backup.iso"
  67.     echo "Writing data from '$fullpath' to '$name'. Please wait until completion. Closure may result in corruption of drives."
  68.     dd if="$fullpath" of="$name" bs=2k
  69.     echo "Done!"
  70. else
  71.     echo "An error occured! Please try again."
  72. fi
Advertisement
Add Comment
Please, Sign In to add comment