Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- # Clone, backup, or restore disks or partition using dd:
- # $1=option, $2=source, and $3=destination
- declare HELP
- HELP="xdd.sh [-c] <source block device | partition> <destination block device | partition>\n
- xdd.sh [-b] <source block device | partition> <destination path>\n
- xdd.sh [-r] <source path> <destination block device | partition>\n
- Warning: If destination is a partition, destination device must contain that\n
- partition.\n
- SYNOPOSIS: Clone, backup and restore partitions and whole\n
- block devices. When cloning, the source and destination block devices do\n
- not need paths, since it is assumed they are listed under /dev. Therefore, sda\n
- expands to /dev/sda. However, a full path is required when listing the\n
- destination with the -b option or the source with the -r option, as these are\n
- archived files.\n
- -------------\n
- Examples:\n
- xdd.sh -c sda sdb: clone drive /dev/sda to drive dev/sdb\n
- xdd.sh -b sda /some/path/backup: creates backup.tar.gz at /some/path\n
- xdd.sh -c /some/path/backup.tar.gz sda: restores image in backup.tar.gz to sda\n"
- read -p "WARNING: incorrect use of $@ may cause DATA LOSS.
- Proceed with caution.
- Press Enter to continue or Ctl-C to cancel."
- if [[ $1=="-h" ]]; then
- # Print help
- echo -e $HELP
- elif [[ $1=="-b" ]]; then
- # Backup disk or partition
- sudo dd if=/dev/"$2" bs=64K conv=noerror,sync | gzip -c > "$3".img.gz
- elif [[ $1=="-c" ]]; then
- # Clone disk or partition
- sudo dd if=/dev/"$2" of=/dev/"$3" bs=64K conv=noerror,sync status=progress
- elif [[ $1=="-r" ]]; then
- # Restore disk or partition
- sudo gunzip -c "$2" | dd of=/dev/"$3"
- else
- echo -e $HELP
- fi
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement