Personal tools
You are here: Home Docs Help! How-tos Image backups with netcat

Image backups with netcat

2.2
No rating set

This How-to applies to: All
This How-to is intended for: Desktop Power User

Transferring large blocks of information across the network between devices

Purpose

This is very useful when working with Virtual Machines or block devices in general. You often need to either transfer the contents of a large block device between machines, back up a block device, or make a copy of a block device.

Prerequisities

Two Linux systems with "netcat" installed.

Step by step

Let's assume you want to make a copy of an LVM partition on a different machine.

  • Take a look at the source server and identify the partition you're looking to copy.
    root@noded:~# lvs
      LV          VG   Attr   LSize   Origin Snap%  Move Log Copy% 
      hydra       vols -wi-ao  10.00G                              
      mgm2        vols -wi-ao   4.00G                              
      relay       vols -wi-ao   5.00G                                
      swap        vols -wi-a- 512.00M                              
      zeo2        vols -wi-ao  40.00G                          
  • Take "relay" in this instance, we will need a 5G partition on the target server. On the target server, create a new LVM partition with the following command;
    lvcreate -L 5G -n relay_copy vols
    # in this instance;
    # 5G is the desired size (make sure it's large enough!)
    # relay_copy is the name of the target block device
    # vols is a volume group on the target system with at least 5G of free space ..
    
  • Now set up a "listener" on the target system which will pipe it's output into your new block device.
    netcat -l -p 8009 > /dev/vols/relay_copy
    # -l = listen
    # -p 8009 = on port 8009
    # > /dev/vols/relay_copy = pipe anything that comes in to our new block device
    
  • Now back on the source server, you can use netcat to pipe the contents of the block device out over the network
    cat /dev/vols/relay | netcat <dest ip> 8009
    # copy the contents of /dev/vols/relay to <dest ip> on port 8009
    
  • Note that the netcat "may" not exit when it's finished, so you can use "vmstat" on the target machine to monitor disk traffic, when the traffic stops simply use "Ctrl-C" on the source system to terminate the process.
    [Anyone know a sure-fire syntax that will make the "cat" command on the source system exit properly?]

Further information

See "man netcat" for more information.

Broadband Deals
Compare the best broadband deals available in the UK from all the leading Internet Service Providers including BT, Sky and Virgin Media.
IT Support Manchester
For IT support, Manchester based MailSure will provide technical support for your IT needs or take control of your IT requirements at any stage in your business development.
IT Support Bristol
IT Services and IT Support provider based in Bristol. Computer maintenance with server support as standard.
Mobile Broadband Deals
Compare the cheapest mobile broadband deals on Mobile Broadband Genie, the independent UK price comparison website.
Project Planning Software
Atlantic Global offers full solutions of project management software, including project planning software, timesheets and more
City Leased Lines
Dedicated 100Mbit fibre optic Internet and Cloud outsourcing in the City of London, call now on 020 7096 9004 or email sales@metro-tek.com
IT Support
For The Best IT Support In London Make Our IT Department Your IT Department. Microsoft Gold Certified Partner.
IT Support London
Efficent IT Support & Hosted Services for SME businesses in and around greater London.
Reliable Web Hosting
Affordable Web Hosting with one click installs for Joomla, Moodle, Wordpress and more!
Data Recovery
Professional data recovery services