Add 'README.move-to-another-server'.
This commit is contained in:
parent
918334e413
commit
e94cccd3e2
84
README.move-to-another-server
Normal file
84
README.move-to-another-server
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
# ------------------------------------------
|
||||||
|
# Moving LXC containers between host systems
|
||||||
|
# ------------------------------------------
|
||||||
|
|
||||||
|
lxc_name=d.mx.oopen.de
|
||||||
|
|
||||||
|
lxc_base_dir_old_system="/data/lxc"
|
||||||
|
lxc_base_dir_new_system="/data/lxc"
|
||||||
|
|
||||||
|
new_host_system="o35.oopen.de"
|
||||||
|
|
||||||
|
# ---
|
||||||
|
# old host system
|
||||||
|
# ---
|
||||||
|
|
||||||
|
# Shutdown the container on old system
|
||||||
|
#
|
||||||
|
lxc-stop -n $lxc_name
|
||||||
|
|
||||||
|
|
||||||
|
# Archive container (rootfs & config)
|
||||||
|
#
|
||||||
|
# Note!:
|
||||||
|
# The --numeric-owner flag is very important! Without it, the container may not
|
||||||
|
# boot because the uid/gids get mangled in the extracted filesystem.
|
||||||
|
#
|
||||||
|
# When tar creates an archive, it preserves user / group ownership information.
|
||||||
|
# By default, when extracting, tar tries to resolve the archive user/group ownership
|
||||||
|
# names with the ids on the system running tar. This is intended to ensure that user
|
||||||
|
# ownership is resolved on the new system, in case the UID numeric values differ b
|
||||||
|
# etween systems.
|
||||||
|
#
|
||||||
|
# This is bad for an LXC filesystem because the numeric uid/gid ownership is intended
|
||||||
|
# to be preserved for the whole filesystem. If it gets resolved to a different value,
|
||||||
|
# bad things happen.
|
||||||
|
#
|
||||||
|
cd "$lxc_base_dir_old_system"
|
||||||
|
tar --numeric-owner -czvf $lxc_name_fs.tar.gz $lxc_name
|
||||||
|
|
||||||
|
|
||||||
|
# Copy the created archive to your new server
|
||||||
|
#
|
||||||
|
rsync -avh $lxc_name_fs.tar.gz ${new_host_system}:${lxc_base_dir_new_system}/
|
||||||
|
|
||||||
|
|
||||||
|
# ---
|
||||||
|
# new host system
|
||||||
|
# ---
|
||||||
|
|
||||||
|
# Extract rootfs (including the lxc config file)
|
||||||
|
#
|
||||||
|
cd "${lxc_base_dir_new_system}"
|
||||||
|
gunzip < $lxc_name_fs.tar.gz | tar --numeric-owner -xvf -
|
||||||
|
|
||||||
|
|
||||||
|
# ---
|
||||||
|
# Replace old ip-addresses with the new one
|
||||||
|
# ---
|
||||||
|
|
||||||
|
old_ipv4="83.223.86.92"
|
||||||
|
new_ipv4="95.217.204.227"
|
||||||
|
old_ipv6="2a01:30:0:13:254:9eff:fed5:e7fd"
|
||||||
|
new_ipv6="2a01:4f9:4a:47e5::227"
|
||||||
|
|
||||||
|
replace_base_dir="/data/lxc/d.mx/rootfs"
|
||||||
|
|
||||||
|
replace_ip_files="
|
||||||
|
${replace_base_dir}//etc/amavis/conf.d/50-user
|
||||||
|
${replace_base_dir}//etc/ipt-firewall/interfaces_ipv4.conf
|
||||||
|
${replace_base_dir}//etc/munin/munin-node.conf
|
||||||
|
${replace_base_dir}//etc/postfix/main.cf
|
||||||
|
${replace_base_dir}//etc/postfix/master.cf
|
||||||
|
${replace_base_dir}//etc/spamassassin/local.cf
|
||||||
|
${replace_base_dir}//usr/local/apache2/conf/extra/httpd-info.conf
|
||||||
|
${replace_base_dir}//usr/local/apache2/conf/vhosts/*.conf
|
||||||
|
"
|
||||||
|
|
||||||
|
for _file in $replace_ip_files ; do
|
||||||
|
if [[ -f "$_file" ]]; then
|
||||||
|
perl -i -n -p -e "s/${old_ipv4}/${new_ipv4}/g" $_file
|
||||||
|
perl -i -n -p -e "s/${old_ipv6}/${new_ipv6}/g" $_file
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
Loading…
Reference in New Issue
Block a user