Backup partition to another machine over the network (CentOS/RHEL)


There are many ways to backup partitions between machines (CIFS, NFS, etc.)

I’ll describe what seems to be the easiest and quickest way, you don’t need to setup services like Samba or NFS here.

Machine A (source) : /dev/hda1 / /dev/hda2 /home /dev/hda3 /tmp

Machine B (target) :

Tools needed : dd (diskdump), gzip, nc (netcat), pv (pipeview : optional)

To save your home partition, on the source machine type this : root@source# dd if=/dev/hda2 | gzip -9 | nc -l -p 9999

**What it does : **it will diskdump /dev/hda2, compress the output and send it to the first machine connecting to nc running on port tcp/9999 (you must open the port in your firewall configuration)

On the target machine, type this : root@target# nc 9999 > hda2.gz

**What it does : **it connects to the source machine and start receiving data from it.. the source machine start running the dd command, pipe it through gzip and send the dataflow to netcat. The target machine pipe it to a file hda2.gz

What about security ? The data travels accross the network in the clear. If you need to transfer file across the internet, you should use a VPN or SSH tunnel (see below)

What’s the pv tool you mentionned above ? pv (pipeview) is useful to display the progress of the data transfer. You would need to pipe the data into pv. pv is available at or on the official homepage :

Source : root@source# dd if=/dev/hda2 | gzip -9 | pv -b | nc -l -p 9999

Target : root@target# nc 9999 | pv -b > hda2.gz

Using SSH tunnels :

Source : root@source# dd if=/dev/hda2 | gzip -9 | pv -b | nc -l -p 9999

Target : root@target# ssh -f -L 29999: root@ sleep 10; nc 29999 | pv -b > hda2.gz

Thanks to the author : Thanks to Philippe for pointing out a mistake in this article.

Thanks for reading this post!

Did you find an issue in this article?

- click on the following Github link
- log into Github with your account
- click on the line number containing the error
- click on the "..." button
- choose "Reference in new issue"
- add a title and your comment
- click "Submit new issue"

Your feedback is much appreciated! πŸ€œπŸΌπŸ€›πŸΌ

You can also drop me a line below!