Antsle Forum

Welcome to our Antsle community! This forum is to connect all Antsle users to post experiences, make user-generated content available for the entire community and more. 

Please note: This forum is about discussing one specific issue at a time. No generalizations. No judgments. Please check the Forum Rules before posting. If you have specific questions about your Antsle and expect a response from our team directly, please continue to use the appropriate channels (email: [email protected]) so every inquiry is tracked. 

Please or Register to create posts and topics.

Moving Antlets from one Antsle to another.

Has anyone been successful yet, moving an antlet as it is configured from one box to another?  either edglinux on your own hardware or to another antsle box?

 

Hi Doug-

These instructions should allow you to export and antlet from one to the other. I'd always recommend experimenting on a test antlet before moving the real one just in case anything gets mixed up in the execution.

Did you intend to include a link to the instructions?

rockandroller has reacted to this post.
rockandroller
Quote from Johannes Dietzel on July 15, 2019, 10:18 am

Hi Doug-

These instructions should allow you to export and antlet from one to the other. I'd always recommend experimenting on a test antlet before moving the real one just in case anything gets mixed up in the execution.

Keen to see these instructions! (Thanks in advance...)

@rockandroller and @doug-knowles.  Sorry about that, I didn't catch the error message that said txt files could be uploaded. Pasting it here below.

EXPORTING ANTLETS

#!/bin/bash

if [ $# -ne 2 ]; then
echo "Usage: export-antlet <antlet-name> <destination-directory>"
echo " "
echo "This utility wil create a file in the destination-directory with"
echo "the following naming convention:"
echo "- antlet_name.date-time.type.ipX.export"
exit 1
fi

debug=0

antlet_name=$1
dest_dir=$2

echo "Calling command: export-antlet $*" | logger -t export-antlet

# Does antlet exist and get antlet type: KVM or LXC
if [ `virsh -c qemu:///system list --name --all|grep "^${antlet_name}$"|wc -l` -eq "1" ]; then
antlet_type=qemu
elif [ `virsh -c lxc:/// list --name --all|grep "^${antlet_name}$"|wc -l` -eq "1" ]; then
antlet_type=lxc
else
echo "antlet '${antlet_name}' does not exist!" | tee /dev/tty | logger -t export-antlet
exit 1
fi

# Remove trailing / in destination path
last_char=${dest_dir: -1}
if [ "$last_char" = "/" ]; then
dest_dir=${dest_dir%?}
fi

# Does the destination path exist
if [ ! -d "$dest_dir" ]; then
echo "'${dest_dir}' is not a directory or does not exist" | tee /dev/tty | logger -t export-antlet
exit 1
fi

# Get antlet zfs path
zfs_path=`zfs list -H -o name | grep "/${antlet_name}$"`

## dumpxml to antlet directory
if [ $debug -eq 1 ]; then echo "+dumpxml $antlet_type"; fi
if [ "$antlet_type" = "qemu" ]; then
virsh -c qemu:///system dumpxml $antlet_name > /${zfs_path}/antlet-libvirt.xml
else
virsh -c lxc:/// dumpxml $antlet_name > /${zfs_path}/antlet-libvirt.xml
fi
echo "${antlet_name}: dumpxml to antlet directory" | logger -t export-antlet

# Get antlet details from xml.. only using mac addr in file name
#memory=`grep "<memory unit" /${zfs_path}/antlet-libvirt.xml | tr -d " " | tr "<>" "\t" | cut -f3`
#cpu=`grep "<vcpu placement" /${zfs_path}/antlet-libvirt.xml| tr -d " " | tr "<>" "\t" | cut -f3`
mac=`grep "<mac address='b2:61:6e" /${zfs_path}/antlet-libvirt.xml | cut -d ":" -f6 | tr -d "'/>" | tr "[a-f]" "[A-F]"`
# convert hex to decimal
ip=`echo "obase=10; ibase=16; $mac" | bc`

# create snapshot
if [ $debug -eq 1 ]; then echo "+snapshot"; fi
(zfs snapshot ${zfs_path}@exportsnap && echo "${antlet_name}: export snapshot created") | logger -t export-antlet

## zfs send to file
if [ $debug -eq 1 ]; then echo "+zfs send"; fi
bu_time=`date +"%Y%m%d-%H%M%S"`
(zfs send ${zfs_path}@exportsnap > ${dest_dir}/${antlet_name}.${bu_time}.${antlet_type}.ip${ip}.export && echo "${antlet_name}: zfs send to ${dest_dir}/${antlet_name}=${bu_time}.export") | logger -t export-antlet

## zfs destroy snapshot
if [ $debug -eq 1 ]; then echo "+zfs destroy"; fi
(zfs destroy ${zfs_path}@exportsnap && echo "${antlet_name}: zfs destroyed ${zfs_path}@exportsnap") | logger -t export-antlet

IMPORTING ANTLETS

#!/bin/bash

# TODO: antlet name must match the name in the xml

if [ $# -ne 3 ]; then
echo "Usage: import-antlet <export_file_name> <destination_zpool> <antlet_name>"
exit 1
fi

export_file=$1
zpool=$2
antlet_name=$3
debug=0

echo "Calling command: import-antlet $*" | logger -t import-antlet

# Does export file exist
if [ $debug -eq 0 ]; then echo "**export file check"; fi;
if [ ! -f "$export_file" ]; then
echo "'$export_file' does not exist" | tee /dev/tty | logger -t import-antlet
exit 1
fi

# Does antlet exist with same name
if [ `virsh -c qemu:///system list --name --all|grep "^${antlet_name}$"|wc -l` -eq "1" ] || [ `virsh -c lxc:/// list --name --all|grep "^${antlet_name}$"|wc -l` -eq "1" ]; then
echo "antlet '${antlet_name}' already exists!" | tee /dev/tty | logger -t export-antlet
exit 1
fi

# Does zpool exist
if [ $debug -eq 0 ]; then echo "**zpool check"; fi;
if [ `zpool list -H -o name | grep "^${zpool}$" | wc -l` -ne 1 ]; then
echo "zpool '${zpool}' does not exist" | tee /dev/tty | logger -t import-antlet
exit 1
fi

# zfs receive from export file
if [ $debug -eq 0 ]; then echo "**zfs receive"; fi;
(zfs receive ${zpool}/$antlet_name < $export_file && echo "zfs receive ${zpool}/$antlet_name < $export_file") | tee /dev/tty | logger -t import-antlet

ret=${PIPESTATUS[0]}
if [ ${ret} -ne 0 ]; then
echo "Could not zfs receive" >&2
exit ${ret}
fi

# remove snapshot @exportsnap
if [ $debug -eq 0 ]; then echo "**zfs destroy"; fi;
(zfs destroy ${zpool}/${antlet_name}@exportsnap && echo "zfs destroy @exportsnap") | logger -t import-antlet

ret=${PIPESTATUS[0]}
if [ ${ret} -ne 0 ]; then
echo "Could not remove @exportsnap" >&2
exit ${ret}
fi

# Get domain type from xml
if [ $debug -eq 0 ]; then echo "**get domain_type from xml"; fi;
domain_type=`head -n 1 /${zpool}/${antlet_name}/antlet-libvirt.xml | cut -d "'" -f2`

ret=${PIPESTATUS[0]}
if [ ${ret} -ne 0 ]; then
echo "Could not get domain type from xml" >&2
exit ${ret}
fi

if [ $debug -eq 0 ]; then echo "**set 'vc' variable"; fi;
case "$domain_type" in

lxc)
vc="lxc:///"
;;
kvm)
vc="qemu:///system"
;;
*)
echo "Unknown domain type <${domain_type}> for antlet $antlet_name" >&2
exit 150
;;
esac

# virsh define domain
if [ $debug -eq 0 ]; then echo "**virsh define"; fi;
(virsh -c "$vc" define /${zpool}/${antlet_name}/antlet-libvirt.xml 2>&1 && echo "Domain $antlet_name created") | logger -t import-antlet

ret=${PIPESTATUS[0]}
if [ ${ret} -ne 0 ]; then
echo "Could not define domain" >&2
exit ${ret}
fi

rockandroller, lancem and doug.knowles have reacted to this post.
rockandrollerlancemdoug.knowles

Thank you so much...   I have successfully moved 2 antlets from one antsle to another.
antlet 1 - Ubuntu 18.04 lxc

antlet 2 - Ubuntu 18.04 kvm

notes for others.

i recommend creating a work directory in /antlets for your import and export files and to remove them when you are done... I used /antlets/export and /antsle/import

the KVM export file was quit large and I ran out of space in the home directory.

 

i actually stopped the existing antlets, exported imported and started them on the new antsle.  Port forwarding and everything was exactly the same and no changes were needed.    Plug and play like they were always there.

rockandroller and doug.knowles have reacted to this post.
rockandrollerdoug.knowles

This would be trivial if Antsle had a decent backup solution. Back up to a USB drive, restore to other Antsle, done. I guess you could do it with the cloud backup but even with gigabit fiber  and no throttling that will be a lot slower.

IOW it is ridiculous that you have to write custom scripts to do this.

rockandroller has reacted to this post.
rockandroller

100% agree, it is a fatal flaw not to have a simple and local VM backup/restore mechanism built in to AntMan.

 

File under: " What were they THINKING?" ...

@bobh and @rockandroller that functionality does not currently exist but is being developed which is why we gave the scripts as a courtesy if anyone wanted to DIY. We laid the foundations for this in our work on Cloud backups and next is local backups in the antMan GUI so hang tight.

rockandroller, sean.rearviewmirror and lancem have reacted to this post.
rockandrollersean.rearviewmirrorlancem