北肙

当你不能够再拥有,唯一可以做的,就是令自己不要忘记。

Data Migration Between Two Linux Hosts

1.   flow chart 2.   data migration a)   preparing the hardware Put the host and the storage specified location; Connect power cable, network cable and fiber; Power on the machines and see if there is no exception; Boot to LSI(when the P400 RAID card is recognized, enter ‘F8’), and configure RAID1 with two disks. b)  Boot […]

1.   flow chart

20161005-1

2.   data migration

a)   preparing the hardware

  • Put the host and the storage specified location;
  • Connect power cable, network cable and fiber;
  • Power on the machines and see if there is no exception;
  • Boot to LSI(when the P400 RAID card is recognized, enter ‘F8’), and configure RAID1 with two disks.

b)  Boot up with Linux LiveCD

  • Boot up with Red Hat Linux Server LiveCD (Desktop distributions did not contain the driver of the RAID CARD) and boot into ‘rescue mode’ with network and make the IP address ‘10.0.0.1/24’ (connected to the source host with straight-though cable, and configure the network card with ‘10.0.0.4’). Choose ‘Skip’ when the screen display the content followed to avoid error when ‘umount’ root partition.

c) Preparing the disks

  • As the version of the Linux in this case is not the latest, the disk still use ‘MBR’partition format, so we will create the partitions with ‘fdisk’tools.
    # fdisk /dev/cciss/c0d0
  • PS: enter the command line, ‘p’ to show the partition information, ‘d’ to delete a partition, ‘n’ to create a new partition (then ‘p’ stand for primary partition and ‘e’ for logical, use like ‘+50M/G’ to limit the size or specify the last sector).

d)  copy system files

  • format the partitions
    # for I in 1 2 3 5 7; do mkfs.ext3 /dev/cciss/c0d0p$I; done
  • format swap partition
    # mkswap /dev/cciss/c0d0p6

e) create mount point for local partitions

# mkdir –p /system/boot
# mkdir –p /system/opt
# mkdir –p /system/home/oracle
# mkdir –p /system/oradata
# mkdir –p /system/proc
# mkdir –p /system/dev
# mkdir –p /system/sys
# mkdir –p /system/run
PS: Do not mount root partition to ‘/mnt’ directory, or you will get a lot of errors later.

f) Mount local partitions to their mount points

# mount /dev/cciss/c0d0p7 /system
# mount /dev/cciss/c0c0p1 /system/boot
# mount /dev/cciss/c0d0p2 /system/home/oracle
# mount /dev/cciss/c0d0p3 /system/opt
# mount /dev/cciss/c0d0p5 /system/oradata

g) copy system files

# for I in `ls / | grep -v 'proc\|dev\|sys\|run\|oradata'`; do rsync –av –progress [email protected]:/$I /system
说明:将源主机根分区下除“proc, dev, sys, run, oradata”外的其它目录保留权限同步到目标主机/system目录下,即本地盘根分区。

h) recover bootloader

  • mount run-time filesystem
    # mount -t proc none /system/proc
    # mount --rbind /dev /system/dev
    # mount --rbind /sys /system/sys
    # mount --rbind /run /system/run
  • change root partition to local disk
    # chroot /system /bin/bash
  • install grub to local disk
    # grub-install --no-floppy /dev/cciss/c0d0
  • fix ‘grub.cfg’ and ‘/etc/fatab’
    If you did not specified the ‘label’ for each partition, then you need to change the line ‘ro root=LABEL=/’ in ‘/boot/grub/grub.cfg’to‘ro root=/dev/cciss/c0d0p7’(c0d0p* is depends your situation).
  • reboot to verify
    # shutdown –r now
    PS: because the size of the data in this case is much less than 146GB, so the storage we prepared is not used.
    

3.   Backup and recover the Oracle database

a)   make level 0 RMAN backup for source host database

# su - oracle
$ cd $ORACLE_HOME
$ bin/rman target /
RMAN> backup incremental level 0 database;
PS: level 1 backup is based on level 0, so we need to make level 0 backup at the beginning.

b)  copy the backup and the control file to target host

  • copy backup files thought the network
    # rsync -av --progress /opt/oracle/flash_recovery_area/backupset/ [email protected]: /opt/oracle/flash_recovery_area/backupset
    PS: the first path is end with ‘/’, so the files inside will copied to directory ‘backupset’ on target host, otherwise copied the directory ‘backupset’ on source host.

c) Copy the control file

# rsync -av --progress /home/oracle/c* [email protected]:/home/oracle
PS: for where is the backup or control file, please check the output of ‘show all’to confirm under RMAN command line. Make sure the path of the source and target hosts are the same.

d)   recover database with RMAN on target host

  • 将目标主机oracle数据库关闭后重新启动数据库实例。
    SQL> shutdown immediate;
    SQL> startup nomount;
  • 恢复控制文件
    RMAN> retore controlfile from '/home/oracle/c-2198842942-20160819-02';
    说明:具体控制文件名称请以实际为准。
  • 读取控制文件
    RMAN> alter database mount;
  • 恢复数据库
    RMAN> restore database;
    RMAN> switch datafile all;
    RMAN> recover database;
  • 验证数据库文件一致性
    SQL> select checkpoint_change# from v$datafile;
    SQL> select FILE#, CHECKPOINT_CHANGE# from v$datafile_header;
    说明:只有两条命令结果中数字均相同时表明数据库一致。
  • 打开数据库
    RMAN> alter database open resetlogs;

4、源主机数据库RMAN 1级备份

RMAN> backup incremental level 1 database;

Leave a Reply

Your email address will not be published. Required fields are marked *