This page (revision-45) was last changed on 23-Apr-2022 17:06 by Harry Metske

This page was created on 23-Apr-2022 17:05 by Harry Metske

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Page revision history

Version Date Modified Size Author Changes ... Change note
45 23-Apr-2022 17:06 24 KB Harry Metske to previous
44 23-Apr-2022 17:05 24 KB Harry Metske to previous | to last
43 23-Apr-2022 17:05 24 KB Harry Metske to previous | to last
42 23-Apr-2022 17:05 24 KB Harry Metske to previous | to last
41 23-Apr-2022 17:05 21 KB Harry Metske to previous | to last

Page References

Incoming links Outgoing links

Version management

Difference between version and

At line 533 added 60 lines
! lxc-rsync
To be able to quickly "copy/clone" lxc's (while having their own filesystem/lv already) :
%%small
{{{
root@apollo:~/bin# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda7 9.2G 5.3G 3.5G 61% /
udev 971M 12K 971M 1% /dev
tmpfs 389M 408K 389M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 972M 0 972M 0% /run/shm
cgroup 972M 0 972M 0% /sys/fs/cgroup
/dev/mapper/vg0-lvol.cn1 20G 7.4G 12G 40% /var/lib/lxc/cn1
/dev/mapper/vg0-lvol.cn4 5.0G 2.0G 2.7G 43% /var/lib/lxc/cn4
/dev/mapper/vg0-lvol.cn2 20G 6.7G 13G 36% /var/lib/lxc/cn2
/dev/mapper/vg0-lvol.cn3 3.0G 69M 2.8G 3% /var/lib/lxc/cn3
}}}
%%
I created the following ~root/bin/lxc-rsync script :
%%small
%%prettify
{{{
#!/bin/bash
#
# rsync on lxc with another
# args: <src lxc> <tgt lxc>
#
NUMARGS=$#
if [ $NUMARGS -ne 2 ]; then
echo "Usage: lxc-rsync <src lxc> <tgt lxc>"
exit 8
fi
SRCLXC=$1
TGTLXC=$2
SRCDIR=/var/lib/lxc/${SRCLXC}/rootfs
TGTDIR=/var/lib/lxc/${TGTLXC}/rootfs
if [ -d $SRCDIR -a -d $TGTDIR ]; then
echo "rsyncing from $SRCLXC to $TGTLXC"
cd $SRCDIR || exit 8
# save the old IP address
OLDIP=`grep address ${TGTDIR}/etc/network/interfaces | awk '{ print $NF}'`
rsync --exclude "tmp" --exclude "dev" --exclude "media" --exclude "mnt" --exclude "proc" --exclude "sys" --exclude "var/run" --verbose --recursive --links --perms --acls --times --owner --group --one-file-system --delete . $TGTDIR
# patching hostname and IP address
echo "patching /etc/hostname, /etc/hosts and /etc/network/interfaces ==> $TGTLXC / $OLDIP"
sed --in-place s/${SRCLXC}/${TGTLXC}/g ${TGTDIR}/etc/hostname
sed --in-place s/${SRCLXC}/${TGTLXC}/g ${TGTDIR}/etc/hosts
WRONGIP=`grep address ${TGTDIR}/etc/network/interfaces | awk '{ print $NF}'`
sed --in-place s/${WRONGIP}/${OLDIP}/g ${TGTDIR}/etc/network/interfaces
else
echo "either $SRCDIR or $TGTDIR does not exist"
exit 8
fi
}}}
%%
%%