Showing posts with label Backup and Restore. Show all posts
Showing posts with label Backup and Restore. Show all posts

DD Netcat bzip

Tonight the Kids Windows 7 PC crashed. Despite my better judgement to just load Ubuntu, I decided to take pitty on their desire to play Windows games. The large disk that origionally came with the PC was put in the media server, so I needed a way to restore from the factory partition over a network connection. I decided to adapt DD and this and this to my needs. Sample only, edit for your needs, and use only parts applicable to your system / task. DO NOT DIRECTLY CUT AND PASTE EVERYTHING WITHOUT THINKING FIRST.

Source disk info:  
fdisk -l /dev/sdc
Disk /dev/sdc: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xf0615ad1

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        2481    19922944   27  Unknown
/dev/sdc2   *        2481        2494      102400    7  HPFS/NTFS
/dev/sdc3            2494      121602   956734464    7  HPFS/NTFS


target disk info: fdisk -l /dev/sdb

Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xf0615ad1

   Device Boot      Start         End      Blocks   Id  System




#Get the partition data
ssh -p 22 [email protected] "dd if=/dev/sdc bs=512 count=1" | dd of=/dev/sdb bs=512 count=1
#Copy first two partitions
ssh -p 22 [email protected] "dd if=/dev/sdc1" | dd of=/dev/sdb1
ssh -p 22 [email protected] "dd if=/dev/sdc2" | dd of=/dev/sdb2

#delete and re-create the third one
fdisk /dev/sdb



Next time, I might try using NetCat if I do not need the encryption that ssh offers:
target disk: 
nc -l 19000 | bzip2 -d | dd bs=8225280 of=/dev/sdb count=1
source disk: 
dd bs=8225280 if=/dev/sdc count=1 | bzip2 -c | nc 10.0.0.1 19000



Another example restore from an old gzip compressed image file on a remote pc:

ssh -p 22 [email protected] "dd if=/your/remote/backup/file\ with\ spaces\ escaped.gz" | gunzip -c -d | sudo dd of=/dev/sda

While above command is running you can check how far along it is by sending USR1 to the dd sda process id:

ps -def | grep dd | grep sda

kill -USR1 $YOUR-DD-PROCESSID