Home  >  Article  >  Operation and Maintenance  >  Remember an example of server website data migration

Remember an example of server website data migration

齐天大圣
齐天大圣Original
2020-05-07 16:39:49193browse

The company's server has a system disk of 40G, which has been used up about 30%. The boss purchased a new disk of 200G and asked me to migrate the previous data to the new disk. The migration went very smoothly. Here I will share with you how I did it.

Format

lsblk View the new disk file name

First we need to know the disk file, use lsblk to view it, and know that the new disk file name is /dev/vdb

Partition

I divided the 200G disk into two areas, with sizes of 50G and 100G respectively. I will keep the remaining 50G to see how to use it later.

# 分区的命令
fdisk /dev/vdb
…… 

# 强制让内核重新找一次分区表
partprobe

# 格式化分区
mkfs.xfs /dev/vdb1
mkfs.xfs /dev/vdb2

Mount

After partitioning and formatting, you need to mount the partition. Partitions under Linux must be mounted before they can be used.

Create a new directory/data to mount /dev/vdb1. This partition is temporarily reserved for future use.

The website data is all in the /www directory. We are going to store the data in this directory on the new disk partition. How to minimize the migration workload?

The method I adopted is to change the original directory /www to /wwwbak, and then re-create the empty directory /www. The /www directory is now empty, so it can be mounted on a new disk partition. We will mount the 100G partition to the /www directory. Then copy all the data in the /wwwbak directory to the /www directory. At this point, the migration work is completed.

# 关闭nginx及mysql服务
killall nginx
killall mysqld

# 将原/www目录修改为/wwwbak
mv /www /wwwbak
# 创建空目录
mkdir /www /data

# 挂载
mount /dev/vdb1 /data
mount /dev/vdb2 /www

Modify the /etc/fstab file

Modify the /etc/fstab file to allow it to be automatically mounted at boot.

# 查看分区的uuid
blkid

# 修改fstab文件内容
vim /etc/fstab
...

# 重新挂载一遍看有没有错误
mount -a

Migrating data

Migrating data is very simple at this time. cp must add option -a so that the file attributes will not change.

# 复制数据
cp -a /wwwbak/* /www

# 开启ningx和mysql
/etc/init.d/nginx start
/etc/init.d/mysql start

After data migration, the /wwwbak directory can be deleted, or you can keep it and make a backup.

The above is the detailed content of Remember an example of server website data migration. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn