Advertisement
rockhazard

xdd.sh

Jan 17th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.67 KB | None | 0 0
  1. #! /bin/bash
  2. # Clone, backup, or restore disks or partition using dd:
  3. # $1=option, $2=source, and $3=destination
  4.  
  5. declare HELP
  6.  
  7. HELP="xdd.sh [-c] <source block device | partition> <destination block device | partition>\n
  8. xdd.sh [-b] <source block device | partition> <destination path>\n
  9. xdd.sh [-r] <source path> <destination block device | partition>\n
  10. Warning: If destination is a partition, destination device must contain that\n
  11. partition.\n
  12.  
  13. SYNOPOSIS: Clone, backup and restore partitions and whole\n
  14. block devices. When cloning, the source and destination block devices do\n
  15. not need paths, since it is assumed they are listed under /dev. Therefore, sda\n
  16. expands to /dev/sda. However, a full path is required when listing the\n
  17. destination with the -b option or the source with the -r option, as these are\n
  18. archived files.\n
  19. -------------\n
  20. Examples:\n
  21. xdd.sh -c sda sdb: clone drive /dev/sda to drive dev/sdb\n
  22. xdd.sh -b sda /some/path/backup: creates backup.tar.gz at /some/path\n
  23. xdd.sh -c /some/path/backup.tar.gz sda: restores image in backup.tar.gz to sda\n"
  24.  
  25. read -p  "WARNING: incorrect use of $@ may cause DATA LOSS.
  26. Proceed with caution.
  27. Press Enter to continue or Ctl-C to cancel."
  28.  
  29. if [[ $1=="-h" ]]; then
  30.     # Print help
  31.     echo -e $HELP
  32. elif [[ $1=="-b" ]]; then
  33.     # Backup disk or partition
  34.     sudo dd if=/dev/"$2" bs=64K conv=noerror,sync | gzip -c > "$3".img.gz
  35. elif [[ $1=="-c" ]]; then
  36.     # Clone disk or partition
  37.     sudo dd if=/dev/"$2" of=/dev/"$3" bs=64K conv=noerror,sync status=progress
  38. elif [[ $1=="-r" ]]; then
  39.     # Restore disk or partition
  40.     sudo gunzip -c "$2" | dd of=/dev/"$3"
  41. else
  42.     echo -e $HELP
  43. fi
  44.  
  45. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement