How to having user metadata on a container?

Hello,

I am doing backup of containers offloading by moving snapshots into a far LXD server, there I am naming target container having source server name and backup suffix, which does fit enough… until…

I added a second LXD server and time to time redistribute main containers across main two LXD servers, so when I move into LXD server for backups the naming of the containers is not pretty, even I am also needing some extra info.

So since then I’m looking for adding properly user metadata.

Can you guide me to the proper way?

So I have around 15 containers and 1 VM, and would like to add on the moved snapshots tags/properties as metadata like this:

Container1:
server_from: lxdsrv02
backup_when: YYMMDD_HHSS

ContainerN:
server_from: lxdsrv01
backup_when: YYMMDD_HHSS

Than you.

I’ve made a proposal for a similar feature. For the time being it seems possible to do things like creating empty profiles, whos purpose is nothing more than to “tag” vms

However, it seems like other parts of the lxd toolchain need to be able to say “do this on …”, so the general need for tagging (which is integrated into the tooling) is apparent. eg you want to be able to start all “boot_xx” servers or run some process to upgrade all “nginx_yy” servers

oook… even so not possible to put metadata on a profile, correct?
So using profile with naming convention telling about what is needed, correct?

Just poped now an idea :bulb: of having some custom file on the container folder and referred some way on the container config, is there such possibility?

Because then inside that custom file… custom mess telling what user/admin needs… :slight_smile:

What do you think?

You can use the user.* config keys for storing user specific info.

2 Likes

That’s it… my results and related ugly shell script:

Ugly script:

#!/bin/bash
SRC_SERVER=$1
TGT_SERVER=$2
CONTAINER=$3
STORAGE_POOL=$4

CONT_BCK_SYNC_AT_SRC="${CONTAINER}-sync-to-${TGT_SERVER}"
CONT_BCK_SYNC_AT_TGT="${CONTAINER}-sync-from-${SRC_SERVER}"
CONT_BCK_REST_AT_TGT="${CONTAINER}-bck"

printf "\n------> $0 $1 $2 $3 $4"
printf "\n---------------------\nStarting:: %s:%s --> %s:%s [%s]\n" "${SRC_SERVER}" "${CONTAINER}" "${TGT_SERVER}" "${CONT_BCK_REST_AT_TGT}" "${STORAGE_POOL}"

printf "+ Deleting possible previous snapshot on source: %s:%s\n" "${SRC_SERVER}" "${CONTAINER}/${CONT_BCK_SYNC_AT_SRC}"
lxc delete ${SRC_SERVER}:${CONTAINER}/${CONT_BCK_SYNC_AT_SRC} -q

printf "+ Snapshoting: %s:%s/%s\n" "${SRC_SERVER}" "${CONTAINER}" "${CONT_BCK_SYNC_AT_SRC}"
SNAP_TIME="$(date +%Y%m%d_%H%M%S)"
lxc snapshot ${SRC_SERVER}:${CONTAINER} ${CONT_BCK_SYNC_AT_SRC} 
printf "+ Deleting possible previous snapshot sync on target: %s:%s\n" "${TGT_SERVER}" "${CONT_BCK_SYNC_AT_TGT}"
lxc delete ${TGT_SERVER}:${CONT_BCK_SYNC_AT_TGT} -q

printf "+ Moving: %s:%s --> %s:%s [%s]\n" "${SRC_SERVER}" "${CONTAINER}/${CONT_BCK_SYNC_AT_SRC}" "${TGT_SERVER}" "${CONT_BCK_SYNC_AT_TGT}" "${STORAGE_POOL}"
lxc move ${SRC_SERVER}:${CONTAINER}/${CONT_BCK_SYNC_AT_SRC} ${TGT_SERVER}:${CONT_BCK_SYNC_AT_TGT} -s ${STORAGE_POOL} -c boot.autostart=false
lxc config set ${TGT_SERVER}:${CONT_BCK_SYNC_AT_TGT} user.backup_snap_src_server=${SRC_SERVER} user.backup_snap_date=${SNAP_TIME} user.backup_to_server=${TGT_SERVER}


printf "+ Delete previous backup on target: %s:%s\n" "${TGT_SERVER}" "${CONT_BCK_REST_AT_TGT}"
lxc delete ${TGT_SERVER}:${CONT_BCK_REST_AT_TGT} -q

printf "+ Renaming: %s:%s --> %s:%s \n" "${TGT_SERVER}" "${CONT_BCK_SYNC_AT_TGT}" "${TGT_SERVER}" "${CONT_BCK_REST_AT_TGT}"
lxc rename ${TGT_SERVER}:${CONT_BCK_SYNC_AT_TGT} ${TGT_SERVER}:${CONT_BCK_REST_AT_TGT}

printf "+ Deleting snapshot on source: %s:%s\n" "${SRC_SERVER}" "${CONTAINER}/${CONT_BCK_SYNC_AT_SRC}"
lxc delete ${SRC_SERVER}:${CONTAINER}/${CONT_BCK_SYNC_AT_SRC}
printf "+ ... Done\n"
printf "\nEnded:: %s:%s --> %s:%s [%s]\n" "${SRC_SERVER}" "${CONTAINER}" "${TGT_SERVER}" "${CONT_BCK_REST_AT_TGT}" "${STORAGE_POOL}"
#EOF

Sample Output

# ./backup_containers.sh srv24 backupsrv94 container-a datastore00

------> ./backup_containers.sh srv24 backupsrv94 container-a datastore00
---------------------
Starting:: srv24:container-a --> backupsrv94:container-a-bck [datastore00]
+ Deleting possible previous snapshot on source: srv24:container-a/container-a-sync-to-backupsrv94
Error: Failed checking instance snapshot exists "srv24:container-a/container-a-sync-to-backupsrv94": Failed to fetch snapshot "container-a-sync-to-backupsrv94" of instance "container-a" in project "default": InstanceSnapshot not found
+ Snapshoting: srv24:container-a/container-a-sync-to-backupsrv94
+ Deleting possible previous snapshot sync on target: backupsrv94:container-a-sync-from-srv24
Error: Failed checking instance exists "backupsrv94:container-a-sync-from-srv24": Instance not found
+ Moving: srv24:container-a/container-a-sync-to-backupsrv94 --> backupsrv94:container-a-sync-from-srv24 [datastore00]
+ Delete previous backup on target: backupsrv94:container-a-bck
+ Renaming: backupsrv94:container-a-sync-from-srv24 --> backupsrv94:container-a-bck 
+ Deleting snapshot on source: srv24:container-a/container-a-sync-to-backupsrv94
Error: Failed checking instance snapshot exists "srv24:container-a/container-a-sync-to-backupsrv94": Failed to fetch snapshot "container-a-sync-to-backupsrv94" of instance "container-a" in project "default": InstanceSnapshot not found
+ ... Done

Ended:: srv24:container-a --> backupsrv94:container-a-bck [datastore00]

On output visible errors are expected due to strategic avoidance of data movement errors.

So solution rely on line:

lxc config set ${TGT_SERVER}:${CONT_BCK_SYNC_AT_TGT} user.backup_snap_src_server=${SRC_SERVER} user.backup_snap_date=${SNAP_TIME} user.backup_to_server=${TGT_SERVER}

Resulting config

...
  image.version: "20.04"
  user.backup_snap_date: "20230518_111453"
  user.backup_snap_src_server: srv24
  user.backup_to_server: backupsrv94
  volatile.apply_template: copy
...

:slight_smile:

Thank you,

1 Like