Cloning and Backing up a Linux based System via Network
From TechnologicalWiki
Let's explain our situation:
We have a local linux based sytem, which name is LocalBox.
Our plan is to back up this system in a second machine, named SecondBox, and on the fly clone our local system in a third box called ThirdBox.
First of all we calculate the space we need to make the backup.
In LocalBox we type:
$df -h
Filesystem Size Used Avail Mounted /dev/sda2 9.4G 3.9G 5.2G / /dev/sda3 98G 228M 93G /home
/dev/sda2 is mounted as root and its size is less than 4 Gigabyte, and when compressed will have a minor size.
home partition has a very small size.
Our estimation is a less than 4 GB size backup needed.
Next step is to seek which filesystems are important for our backup and avoid all virtual filesystems.
$mount
/dev/sda2 on / type ext3 proc on /proc type proc sysfs on /sys type sysfs debugfs on /sys/kernel/debug type debugfs udev on /dev type tmpfs devpts on /dev/pts type devpts /dev/sda3 on /home type ext3 securityfs on /sys/kernel/security type securityfs
/root filesystem will be base directory for our backup.
/proc and /sys will be excluded because they are virtual system directories.
/dev is a virtual directory to store devices, created by udev.
/tmp is where temporary files are stored, will be excluded too.
We are interested only in the base system, so /media and /mnt will also be excluded.
Tar is the tool we use to perform the backup and data will be sent over the network using netcat command. See (3) line.
(3)LocalBox#tar cvjpf - --same-owner --exclude=/proc/* --exclude=/media/* --exclude=/dev/* --exclude=/mnt/* --exclude=/sys/* --exclude=/tmp/* --exclude=./error.log / 2>./error.log | netcat 10.100.100.22 6666
In SecondBox netcat will listen to 6666 port, save data in Backup.tbz file and resend it over the network through 7777 port.
(2)SecondBox$nc nc -l -p 6666 | tee Backup.tbz | nc 10.100.100.29 7777
We previously prepare a partition where we are going to clone our system. e.g: /dev/hda7
ThirdBox#mkfs.ext3 -b 4096 -L SuseClon /dev/hda7
ThirdBox#mount /dev/hda7 /mnt
And in the end ThirdBox listens to 7777 port and restores LocalBox system in /mnt where /dev/hda is mounted.
(1)ThirdBox#nc -l -p 7777 | tar xvjf - -C /mnt
VERY IMPORTANT NOTE:
(1) should be executed first, then (2) and latest (3)


