[CentOS] Data migration from one server to another- Centos 7

Mon Aug 12 14:45:54 UTC 2019
mark <m.roth at 5-cent.us>

Matt Zand wrote:
> I want to move all my OS, services like Apache configuration and
> application (web server) files and folders to another brand new server.
> Both servers are running on Centos 7. i want to  clone everything.
>
>
> My questions
> 1- what is the easiest way to do this?
> 2- do I need to partition hard-drive of new server exactly as old one?
> 3- Is there any changes to make on new server after full migration?
> 4- will root and other user credentials stay the same?
>
>
> Any other suggestion appreciated,
>

>From our documentation wiki at work:

     Log in to the host that needs upgrading or reloading.

    Create directories to hold the new file system:

mkdir /new
mkdir /boot/new


    Rsync the files from the machine you are copying

rsync -HPavzx --exclude=/old --exclude=/var/log/wtmp
--exclude=/var/log/lastlog $machine:/. /new/.
rsync -HPavzx $machine:/boot/. /boot/new/.


    After the copy, check these files:

    /boot/new/grub/device.map - should list the correct device name for hd0
    /new/etc/fstab - should have the correct labels for file systems
    /new/etc/sysconfig/network - edit to list the correct hostname (or
localhost.localdomain if DHCP enabled)
    /new/etc/sysconfig/network-scripts/ifcfg-ethX - remove or edit the
line with "HWADDR"
    /new/etc/modprobe.conf - edit or copy from the original file to
include all devices p
    /new/etc/exports - add or remove exported file systems
    diff -u /boot/grub/device.map /boot/new/grub/device.map
    diff -u /etc/fstab /new/etc/fstab
    diff -u /etc/sysconfig/network /new/etc/sysconfig/network
    diff -u /etc/modprobe.conf /new/etc/modprobe.conf
    diff -u /etc/exports /new/etc/exports

    To prevent problems with kudzu and the Ethernet interfaces:

rsync -HPavzx /etc/sysconfig/network-scripts/ifcfg-eth*
/new/etc/sysconfig/network-scripts
rsync -HPavzx /etc/sysconfig/hwconf /new/etc/sysconfig
rsync -HPavzx /boot/grub/device.map /boot/new/grub/
rsync -HPavzx /etc/udev/rules.d/70-persistent-net.rules
/new/etc/udev/rules.d/

The last, above, is extremely important starting with CentOS 6. Without
that, you might find that eth0 is, in fact, eth4 or some such.

Also, on the new machine, run

 find /new/var/log/ -type f -exec cp /dev/null {} \;

This will truncate all the copies logfiles from the source of the clone,
but leave directories, etc, existing, and with the correct permissions.

    Add a single user kernel option to grub.conf file. Grub doesn't always
allow you to edit the startup options because of a mismatched grub
versions.
    Verify the Grub root and kernel lines reference the correct hard drive
partitions.

Finally, apply labels to the filesystem:

 e2label /dev/sda1 /boot
 e2label /dev/sda3 /
 swapoff -av
 mkswap -L SWAP-sda2 /dev/sda2
 swapon -av

then verify that the labels match /new/etc/fstab. After doing this, edit
/boot/grub/grub.conf, and make sure that the root= parameter on the kernel
line matches the label (root=LABEL=/), not some randomly-generated UUID.
Additional things to copy

Check to see what services are running currently.

If a webserver was running on the old server,

 rsync -HPavzx /old/etc/httpd/conf.d/* /etc/httpd/conf.d/

If siteminder was running,

 rsync -HPavzx /old/etc/httpd/conf/* /etc/httpd/conf/
 rsync -HPavzx /old/usr/local/opt /usr/local/

And either

 rsync -HPavzx /old/public /

or

 rsync -HPavzx /old/var/www/html/* /var/www/html/

If this is an h/a cluster, make sure heartbeat is installed, and

 rsync -HPavzx /old/etc/ha.d/* /etc/ha.d/

If this is a compute cluster node, go to the cluster head node and follow
the instructions for configuration at PBS/torque for adding a new node.

If this system is using Linux RAID,

 rsync -HPavx /old/etc/md.conf /etc/

Also make sure that /etc/fstab is correct.

NOTE: it appears that the ramdisk contains information about RAID. It
might be better to install a minimal system, upgrade it in place, then
rsync /, but not /boot.
SSH keys - Important

Copy the original SSH keys:

rsync -HPavzx /etc/ssh/ssh_host* /new/etc/ssh

Rotation

Move things live, after running: zmodload zsh/files

Swap the old and new directory structures around on both / and /boot.

zsh
zmodload zsh/files

cd /boot
mkdir old
mv * old
mv old/lost+found .
mv old/new/* .

# Root partition.
cd /
mkdir old
mv * old
mv old/lost+found .
#mv old/root . -- WHY?
mv old/scratch .
mv old/new/* .

sync
sync

Make selinux reset all the security file labels

touch /.autorelabel

    Create a single user option in /etc/grub.conf file if this isnt a
routine upgrade.
    Reboot to the upgraded OS (init 6).
    You may need to do the 'use the old kernel' trick including copying
over the kernel and modules, removing the new kernel and putting it
back.

/boot   - kernel files
/lib/modules - kernel modules

Ooops! I forgot to run zmodload zsh/files

If you fail to run zmodload zsh/files, whilst doing an rsync upgrade, you
can do the following

       MODULE_PATH=/old/usr/lib64/zsh/4.3.4
       zmodload zsh/files

to recover.
Check the filesystem labels match /etc/fstab

The ext2 and ext3 file system labels need to match the mounting
information in /etc/fstab

mount | egrep '^/dev/' | while read dev on mnt rest
do
  echo -n 'LABEL='
  e2label $dev
  egrep " $mnt " /etc/fstab
  echo
done

     mark





>
> Matt Zand
> Cell: 202-420-9192
> Work: 240-200-6131
> High School Technology Services <https://myhsts.org/>
> DC Web Makers <https://dcwebmakers.com/>
> Coding Bootcamps <https://coding-bootcamps.com/>
> _______________________________________________
> CentOS mailing list
> CentOS at centos.org
> https://lists.centos.org/mailman/listinfo/centos
>
>