CentOS Overlay数据迁移步骤
systemctl stop docker
。rsync是高效的文件同步工具,适合大规模数据迁移,且支持增量同步。
rsync -aAXv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} /path/to/source/overlay /path/to/destination/
其中:-aAXv
表示归档模式、保留ACL和扩展属性、详细输出;--exclude
用于排除无需迁移的系统目录。mount -t overlay overlay -o lowerdir=/path/to/destination/overlay:/path/to/upperdir:/path/to/workdir /path/to/mountpoint
tar适合打包整个Overlay目录,便于存储或传输。
tar -cvpzf overlay.tar.gz /path/to/source/overlay
-cvpzf
表示创建归档、显示进度、保留权限、使用gzip压缩。tar -xvpzf overlay.tar.gz -C /path/to/destination/ # 解包到目标位置
mount -t overlay overlay -o lowerdir=/path/to/destination/overlay:/path/to/upperdir:/path/to/workdir /path/to/mountpoint # 更新挂载点
cpio适合处理大量小文件,但操作相对复杂。
find /path/to/source/overlay -print | cpio -o -H newc | gzip > overlay.cpio.gz
find
查找文件,cpio -o
打包,-H newc
指定归档格式,gzip
压缩。mkdir -p /path/to/destination/overlay # 创建目标目录
gunzip -c overlay.cpio.gz | cpio -idmv # 解包到目标位置
mount -t overlay overlay -o lowerdir=/path/to/destination/overlay:/path/to/upperdir:/path/to/workdir /path/to/mountpoint # 更新挂载点
mount | grep overlay
确认Overlay文件系统已正确挂载到目标位置。chown
、chmod
调整)。overlay
、工作目录workdir
)已正确迁移或配置。