Last active
January 6, 2025 10:41
-
-
Save vijinho/16d0b6fdedc3f060543576ce8c718ec3 to your computer and use it in GitHub Desktop.
Windows 10 backup script to back up the standard windows installation on a give device - USE AT YOUR OWN RISK!!!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Improved Windows 10 backup script to backup a Windows 10 installation (EFI or MBR) using the /dev/ name, e.g. if on sda run "sh win10backup.sh sda" | |
| PART=$1 | |
| # Check if partition is provided | |
| if [ -z "$PART" ]; then | |
| echo "Error: Partition not specified" | |
| exit 1 | |
| fi | |
| date | |
| echo "Saving partition map of ${PART}..." | |
| fdisk -l /dev/${PART} > ${PART}.fdisk | |
| # Check if fdisk command was successful | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to get partition map" | |
| exit 1 | |
| fi | |
| cat ${PART}.fdisk | |
| echo "Saving boot sector of ${PART}..." | |
| dd bs=2048 count=1 if=/dev/${PART} of=${PART}.mbr | |
| # Check if dd command was successful | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to save boot sector" | |
| exit 1 | |
| fi | |
| # Save EFI Partition | |
| echo "Saving EFI Partition..." | |
| ddrescue -v -N -D -d -r 3 -R -f /dev/${PART}2 ${PART}2.ddr | |
| # Check if ddrescue command was successful | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to save EFI partition" | |
| exit 1 | |
| fi | |
| # Save MS Reserved Partition (if present) | |
| echo "Saving MS Reserved Partition..." | |
| ddrescue -v -N -D -d -r 3 -R -f /dev/${PART}3 ${PART}3.ddr | |
| for p in 1 4; do | |
| echo "Backing up ${PART}{$p}..." | |
| # Check if partition exists | |
| if [ ! -b "/dev/${PART}${p}" ]; then | |
| echo "Warning: Partition ${PART}${p} does not exist. Skipping backup" | |
| continue | |
| fi | |
| ntfsclone -t --new-half-serial --save-image -o - "/dev/${PART}${p}" | gzip -c > "${PART}${p}.ntfsclone.gz" | |
| # Check if ntfsclone command was successful | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to backup partition ${PART}${p}" | |
| exit 1 | |
| fi | |
| done | |
| echo "Done!" | |
| date | |
| exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment