Files
selfhosted-apps-docker/esxi
DoTheEvo c504157db3 update
2023-04-16 10:38:11 +02:00
..
2023-04-16 10:38:11 +02:00

Esxi

guide-by-example

Purpose

Type 1 hypervisor hosting virtual machines, running straight on metal.

Basic settings

https://www.dbappweb.com/2020/08/20/how-to-change-the-default-gateway-for-vmware-vsphere-esxi/

  • esxcfg-route
  • esxcfg-route 10.65.26.25

https://blog.techygeekshome.info/2021/04/vmware-esxi-esxcli-commands-to-update-host-dns-servers/

  • esxcli network ip dns server add --server=8.8.8.8
  • esxcli network ip dns server remove --server=1.1.1.1
  • esxcli network ip dns server list

Backups using ghettoVCB

The script makes snapshot of a VM, copies the "old" vmdk and other files to a backup location, then deletes the snapshot.
This approach, where backup in time is full backup takes up a lot of space. Some form of deduplication might be a solution.

VMs that have any existing snapshot wont get backed up.

Files that are backed up:

  • vmdk - virtual disk file, every virtual disk has a separate file. In webgui datastore browser only one vmdk file is seen per disk, but on filesystem theres blabla.vmdk and blablka-flat.vmdk. The flat one is where the data actually are, the other one is a descriptor file.
  • nvram - bios settings of a VM
  • vmx - virtual machine settings, can be edited

Backup storage locations

  • Local disk datastore
  • NFS share
    For nfs share on trueNAS scale
    • Maproot User -> root
    • Maproot Group -> nogroup

Note the exact path from webgui of your datastore for backups.
Looks like this /vmfs/volumes/6187f7e1-c584077c-d7f6-3c4937073090

Install

  • ssh in to esxi
  • cd /tmp
  • esxcli network firewall ruleset set -e true -r httpClient
  • wget https://github.com/lamw/ghettoVCB/releases/download/2021_10_20/vghetto-ghettoVCB.vib --no-check-certificate
  • esxcli software vib install -v /tmp/vghetto-ghettoVCB.vib -f
  • check ls /opt

Config and preparation

Gotta know basics how to edit files with ancient vi

  • Config file template is in /opt/ghettovcb/ghettoVCB.conf
    Make copy of it cp /opt/ghettovcb/ghettoVCB.conf /opt/ghettovcb/ghetto_1.conf
  • Only edit this file, for starter setting where to copy backups
    vi /opt/ghettovcb/ghetto_1.conf
    VM_BACKUP_VOLUME=/vmfs/volumes/6187f7e1-c584077c-d7f6-3c4937073090/Backups
  • Create a file that will contain list of VMs to backup
    touch /opt/ghettovcb/vms_to_backup_list
    vi /opt/ghettovcb/vms_to_backup_list
    OPNsense
    Arch-Docker-Host
    
  • Create a shell script that starts ghetto script using this config for listed VMs
    touch /opt/ghettovcb/bin/ghetto_run.sh
    vi /opt/ghettovcb/bin/ghetto_run.sh
    #!/bin/sh
    
    /opt/ghettovcb/bin/ghettoVCB.sh \
        -g /opt/ghettovcb/ghetto_1.conf \
        -f /opt/ghettovcb/vms_to_backup_list \
        &> /dev/null
    
    Make the script executable
    chmod +x /opt/ghettovcb/bin/ghetto_run.sh
  • for my use case where TrueNAS VM cant be snapshoted while running because of a passthrough pcie HBA card there needs to be another config
  • Make new config copy
    cp /opt/ghettovcb/ghetto_1.conf /opt/ghettovcb/ghetto_2.conf
  • Edit the config, setting it to shut down VMs before backup.
    vi /opt/ghettovcb/ghetto_2.conf
    POWER_VM_DOWN_BEFORE_BACKUP=1
  • edit the run script, add another execution for specific VM using ghetto_2.conf
    vi /opt/ghettovcb/bin/ghetto_run.sh
    #!/bin/sh
    
    /opt/ghettovcb/bin/ghettoVCB.sh \
        -g /opt/ghettovcb/ghetto_1.conf \
        -f /opt/ghettovcb/vms_to_backup_list \
        &> /dev/null
    
    /opt/ghettovcb/bin/ghettoVCB.sh \
        -g /opt/ghettovcb/ghetto_2.conf \
        -m TrueNAS_scale \
        &> /dev/null
    

Execution and scheduled runs

To simply execute:

  • /opt/ghettovcb/bin/ghetto_run.sh

To execute it periodicly cron is used.

  • Make backup of roots crontab
    cp /var/spool/cron/crontabs/root /var/spool/cron/crontabs/root.backup
  • Edit roots crontab to execute the run script at 4:00
    add the following line at the end in cron format
    vi /var/spool/cron/crontabs/root
    0    4    *   *   *   /opt/ghettovcb/bin/ghetto_run.sh
    
    To save read only file in vi use :wq!
  • restart cron service
    kill $(cat /var/run/crond.pid)
    crond

Restore from backup

Documentation

Logs about backups are in /tmp

disk reclamation

Switching from Thick to Thin disks

vmkfstools --punchzero "./TrueNAS_scale-thin.vmdk"

unmap, windows, fsck_ufs -Ey /dev/da0p3

links

email