chuggerguy

backupwindowsdrive

Dec 25th, 2024
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.64 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # ensure running as root
  4. if [ "$(id -u)" != "0" ]; then
  5.   exec sudo "$0" "$@"
  6. fi
  7.  
  8.  
  9. windowsmount=`fdisk -l | grep "Microsoft reserved" | awk -F" " '{print $1}'`
  10.  
  11.  
  12. if [[ $windowsmount == *"nvme"* ]]; then
  13.      windowsmount=${windowsmount::-2};
  14. else
  15.      windowsmount=${windowsmount::-1};
  16. fi
  17.  
  18.  
  19. backupname="`hostname`_windows_backup_`date '+%Y-%m-%d'`_.img.gz"
  20. user=$SUDO_USER
  21.  
  22.  
  23. bash -c "dd status=progress if=$windowsmount | gzip > $backupname ; chown $user:$user $backupname"
  24.  
  25.  
  26.  
  27.  
  28. # to restore... something like this:
  29. # gzip -d -c {backup.img.gz} | dd status=progress of={where}
  30. # run the restore as root, not sudo
  31.  
  32.  
  33.  
Advertisement
Add Comment
Please, Sign In to add comment