[SOLVED] Reimporting LXC Containers ? Possibilities?

jbwilltx

New Member
Apr 12, 2024
3
0
1
I made a couple of foolish mistakes in a wrong terminal window that resulted in me nuking the lxc configuration files for a server. This degraded into more bad decisions and I ended up having to reinstall the gui.

I still have the containers running so I'm not totally screwed, and I have pbs with backups for the stuff I care about. Is there any possibility of scraping the pbs backups for the LXC metadata, seed that to the reinstalled GUI and get a lock on those?

Two of the containers on this system cannot go down until a scheduled window, so I have to be cool about how I touched them. What would be the recommended action here, any tips appreciated.
 
I did write a little helper, thinking I would copy it in and map it, but that only partially worked. It created the container placeholders in the GUI, but it did not update the configurations.

Bash:
CT=109; N=$(hostname)

SRC="/var/lib/lxc/$CT/config"

POOL=$(zfs list -H -o name 2>/dev/null | awk -F/ '/subvol-'"$CT"'-disk-0/{print $1; exit}')

DS=$(zfs list -H -o name 2>/dev/null | awk '/subvol-'"$CT"'-disk-0/{print $1; exit}')

BR=$(awk -F= '/^lxc.net.0.link=/{print $2}' "$SRC")

MAC=$(awk -F= '/^lxc.net.0.hwaddr=/{print $2}' "$SRC")

MEM=$(awk -F= '/memory.limit_in_bytes|memory.max/{m=$2} END{if(m~/^[0-9]+$/) printf "%d", m/1024/1024}' "$SRC")



CONF="/etc/pve/nodes/$N/lxc/$CT.conf"; mkdir -p "$(dirname "$CONF")"

{

  echo "arch: amd64"

  echo "hostname: ct-$CT"

  echo "unprivileged: 1"

  [[ -n "$DS" && -n "$POOL" ]] && echo "rootfs: $POOL:${DS#${POOL}/}" || \

    awk -F= '/^lxc.rootfs.path=/{print "rootfs: "$2}' "$SRC"

  echo -n "net0: name=eth0,bridge=${BR:-vmbr0}"

  [[ -n "$MAC" ]] && echo ",hwaddr=$MAC" || echo

  [[ -n "$MEM" ]] && echo "memory: $MEM"

} > "$CONF"

chmod 640 "$CONF"; chgrp www-data "$CONF" 2>/dev/null || true

systemctl restart pvedaemon pvestatd

pct config $CT




Bash:
/etc/pve/lxc# N=$(hostname)
mkdir -p /etc/pve/nodes/$N/lxc

for cfg in /var/lib/lxc/*/config; do
  ct=$(basename "$(dirname "$cfg")")
  cp -a "$cfg" "/etc/pve/nodes/$N/lxc/${ct}.conf"
done

chown root:www-data /etc/pve/nodes/$N/lxc/*.conf
chmod 640 /etc/pve/nodes/$N/lxc/*.conf
cp: failed to preserve ownership for '/etc/pve/nodes/txvs02/lxc/107.conf': Operation not permitted
cp: failed to preserve ownership for '/etc/pve/nodes/txvs02/lxc/108.conf': Operation not permitted
cp: failed to preserve ownership for '/etc/pve/nodes/txvs02/lxc/109.conf': Operation not permitted
cp: failed to preserve ownership for '/etc/pve/nodes/txvs02/lxc/110.conf': Operation not permitted
cp: failed to preserve ownership for '/etc/pve/nodes/txvs02/lxc/115.conf': Operation not permitted
cp: failed to preserve ownership for '/etc/pve/nodes/txvs02/lxc/116.conf': Operation not permitted
cp: failed to preserve ownership for '/etc/pve/nodes/txvs02/lxc/120.conf': Operation not permitted
cp: failed to preserve ownership for '/etc/pve/nodes/txvs02/lxc/122.conf': Operation not permitted
cp: failed to preserve ownership for '/etc/pve/nodes/txvs02/lxc/124.conf': Operation not permitted
cp: failed to preserve ownership for '/etc/pve/nodes/txvs02/lxc/131.conf': Operation not permitted
cp: failed to preserve ownership for '/etc/pve/nodes/txvs02/lxc/149.conf': Operation not permitted
cp: failed to preserve ownership for '/etc/pve/nodes/txvs02/lxc/154.conf': Operation not permitted
cp: failed to preserve ownership for '/etc/pve/nodes/txvs02/lxc/155.conf': Operation not permitted
cp: failed to preserve ownership for '/etc/pve/nodes/txvs02/lxc/156.conf': Operation not permitted
cp: failed to preserve ownership for '/etc/pve/nodes/txvs02/lxc/157.conf': Operation not permitted
cp: failed to preserve ownership for '/etc/pve/nodes/txvs02/lxc/300.conf': Operation not permitted
cp: failed to preserve ownership for '/etc/pve/nodes/txvs02/lxc/307.conf': Operation not permitted

I thought this would work but did not consider there is a change in the certificate when I reinstalled the GUI. So definitely not the wisest play on my part, but I feel like this should be recoverable without having to restore from a backup. I havent started untaring backups looking for conf data because Im 2 for 2 and that means next time I break it.