V2V
一共有 4 個步驟
- 設定目標主機的 rsyncd
- First time sync data
- Config VPS & Test
- Final sync
Install rsyncd
dnf install rsync-daemon # R8
設定目標主機的 rsyncd
/etc/rsyncd.conf
use chroot = yes max connections = 4 timeout = 300 log file = /var/log/rsyncd.log strict modes = yes uid = root gid = root list = no port = 1873 strict modes = yes secrets file = /etc/rsyncd.secrets [mailserver] path = /lxc/mail/rootfs read only = no auth users = mailserver
PW File
touch /etc/rsyncd.secrets
chmod 600 /etc/rsyncd.secrets
Enable Service
systemctl restart rsyncd
Firewall
firewall-cmd --permanent \
--add-rich-rule='rule family="ipv4" source address="x.x.x.x" port protocol="tcp" port="1873" accept'
firewall-cmd --reload
First time sync data
On Source
mkdir /root/v2v/
touch /root/v2v/pw.txt; chmod 600 /root/v2v/pw.txt
# 只 sync "/", 不 sync data
mkdir /mnt/rootfs
mount -o noatime /dev/sda3 /mnt/rootfs
/root/v2v/v2v-first.sh
#!/bin/bash # # use rsyncd with password sync Local to Remote host # Dst=R.R.R.R Port=1873 # 不用 default port Module=mailserver bwlimit=8192 # 80 MB/s LogPath=/root/v2v Src=/mnt/rootfs echo -n "Are you want to run v2v script?(y/n) " read input if [ "$input" == "y" ] then rm -f $LogPath/file1.log $LogPath/err1.log 2> /dev/null echo "Start: `date +%H:%M:%S`" rsync -avzAHX --numeric-ids ${Src}/ \ --exclude-from=/root/v2v/exclude1.txt \ --bwlimit=$bwlimit \ --password-file=/root/v2v/pw.txt \ rsync://$Module@$Dst:$Port/$Module > $LogPath/file1.log 2> $LogPath/err1.log echo "End: `date +%H:%M:%S`" fi echo "Done"
/root/v2v/exclude1.txt
# Folders
lost+found
/sys/*
/proc/*
/dev/*
/boot/*
/tmp/*
/selinux/*
/cgroup/*
# Files
aquota.group
aquota.user
# Cust
/root/v2v
/backup/*
/mnt/backup/*
_X
Remark
* 不使用 sshd 而用 rsyncd 原因是因為它不用加密, CPU 佔用率較低
Config VPS & Test
A) Config VPS
...
B) Test
測試閞機 (在 lxc hypervisor)
# 用 "-F" for debug
lxc-start -n ispconfig -F
Final sync
exclude2.txt
# Folders lost+found /sys/* /proc/* /dev/* /boot/* /tmp/* /selinux/* /cgroup/* # Files aquota.group aquota.user # Cust /root/v2v /backup/* /mnt/backup/* _X # 第二次不用 rsync 以下 folder, 因為它們已有 lxc 的 setting /etc /root
v2v-final.sh
#!/bin/bash # Final sync Dst=R.R.R.R Port=1873 # 不用 default port Module=mailserver bwlimit=8192 # 80 MB/s LogPath=/root/v2v Src=/mnt/rootfs echo -n "Are you want to run v2v script?(y/n) " read input if [ "$input" == "y" ] then rm -f $LogPath/file2.log $LogPath/err2.log 2> /dev/null echo "Start: `date +%H:%M:%S`" rsync -avzAHX --numeric-ids --delete ${Src}/ \ --exclude-from=/root/v2v/exclude2.txt \ --bwlimit=$bwlimit \ --password-file=/root/v2v/pw.txt \ rsync://$Module@$Dst:$Port/$Module > $LogPath/file2.log 2> $LogPath/err2.log echo "End: `date +%H:%M:%S`" fi echo "Done"