Difference between revisions of "ESXi - ghettoVCB"

From The TinkerNet Wiki
Jump to navigation Jump to search
Line 14: Line 14:
 
#*''<small><sub>wget <nowiki>http://web.tinkernow.net/otherfiles/ghettoVCB.zip</nowiki></sub></small>''
 
#*''<small><sub>wget <nowiki>http://web.tinkernow.net/otherfiles/ghettoVCB.zip</nowiki></sub></small>''
 
#**''<sup><small>(inside my local network...)</small></sup>''
 
#**''<sup><small>(inside my local network...)</small></sup>''
#*wget <nowiki>://tinker.farted.net/otherfiles/ghettoVCB.zip</nowiki>
+
#*wget <nowiki>http://tinker.farted.net/otherfiles/ghettoVCB.zip</nowiki>
#**(a copy accessible to wge<nowiki/>t without https)
+
#**(a copy accessible to wget without https)
 
#Unpack & rename ghettoVCB
 
#Unpack & rename ghettoVCB
 
#*<code>unzip ghettoVCB.zip</code>
 
#*<code>unzip ghettoVCB.zip</code>

Revision as of 16:37, 1 June 2020

Installation

Install ghettoVCB

  1. SSH (as root) into the machine
  2. Create a Utilities folder on an existing datastore
    • mkdir "/vmfs/volumes/Alpha/Utility_Room/"
    • (This exact location is specific to my testbed server...)
    • Remember this location... It'll be very useful...
  3. switch to this folder
    • cd "/vmfs/volumes/Alpha/Utility_Room/"
  4. download ghettoVCB
    • wget https://github.com/lamw/ghettoVCB/archive/master.zip
      • (wget doesn't seem to like https...)
    • wget http://web.tinkernow.net/otherfiles/ghettoVCB.zip
      • (inside my local network...)
    • wget http://tinker.farted.net/otherfiles/ghettoVCB.zip
      • (a copy accessible to wget without https)
  5. Unpack & rename ghettoVCB
    • unzip ghettoVCB.zip
    • mv ghettoVCB-master ghettoVCB
  6. switch to the new folder
    • cd ghettoVCB
  7. Install it!
    • esxcli software vib install -v "/vmfs/volumes/Alpha/Utility_Room/ghettoVCB/vghetto-ghettoVCB.vib" -f

Have ya noticed the usefulness of remembering "/vmfs/volumes/Alpha/Utility_Room/" yet?

Create a Backup folder on the datastore

mkdir "/vmfs/volumes/Beta/BACKUPS"

ghettoVCB will create subfolders for each VM you backup inside this folder.

Configuration

vi ghettoVCB.conf

VM_BACKUP_VOLUME="/vmfs/volumes/Beta/BACKUPS"
DISK_BACKUP_FORMAT=thin
VM_BACKUP_ROTATION_COUNT=3
POWER_VM_DOWN_BEFORE_BACKUP=0
ENABLE_HARD_POWER_OFF=0
ITER_TO_WAIT_SHUTDOWN=3
POWER_DOWN_TIMEOUT=5
ENABLE_COMPRESSION=0
VM_SNAPSHOT_MEMORY=0
VM_SNAPSHOT_QUIESCE=0
ALLOW_VMS_WITH_SNAPSHOTS_TO_BE_BACKEDUP=0
ENABLE_NON_PERSISTENT_NFS=0
UNMOUNT_NFS=0
NFS_SERVER=
NFS_VERSION=
NFS_MOUNT=
NFS_LOCAL_NAME=
NFS_VM_BACKUP_DIR=
SNAPSHOT_TIMEOUT=15
EMAIL_ALERT=0
EMAIL_LOG=0
EMAIL_SERVER=
EMAIL_SERVER_PORT=25
EMAIL_DELAY_INTERVAL=1
EMAIL_USER_NAME=
EMAIL_USER_PASSWORD=
EMAIL_TO=
EMAIL_ERRORS_TO=
EMAIL_FROM=
WORKDIR_DEBUG=0
VM_SHUTDOWN_ORDER=
VM_STARTUP_ORDER=

(just an example...)

You may note that there are A LOT of things you can configure here.

The important one here is the first line where it points to your backup folder.

Sadly, vi seems to be the only editor available under ESXi. Somebody remind my to write up a tutorial for using it... For now, look here.

Testing

I'm using a VM called "Manager" as my test...

./ghettoVCB.sh -g ./ghettoVCB.conf -m "Manager" -d dryrun

If you see "info: ###### Final status: OK, only a dryrun. ######", it's OK.

Now you can do a real backup...

./ghettoVCB.sh -g ./ghettoVCB.conf -m "Manager"

When you see: "info: ###### Final status: All VMs backed up OK! ######", congratulations, you have a manual backup.

Restoring a VM

Edit the input file for ghettoVCB-restore

vi vms_to_restore

#"<DIRECTORY or .TGZ>;<DATASTORE_TO_RESTORE_TO>;<DISK_FORMAT_TO_RESTORE>;<OPTIONAL_RESTORED_VM_DISPLAY_NAME>"
# DISK_FORMATS
# 1 = zeroedthick
# 2 = 2gbsparse
# 3 = thin
# 4 = eagerzeroedthick
### To restore the VM back to its original name (DELETE the original first!):
#/vmfs/volumes/Beta/BACKUPS/Manager/Manager-2019-09-08_21-01-00;/vmfs/volumes/Alpha;1
### To duplicate the VM under a new name:
/vmfs/volumes/Beta/BACKUPS/Manager/Manager-2019-09-08_21-01-00;/vmfs/volumes/Alpha;1;FooBar

(just an example...

I'm restoring a backup of "Manager", but renaming it to "FooBar" in the process. This is a potential way to rapidly duplicate preconfigured VMs.)

The "/vmfs/volumes/Beta/BACKUPS/Manager/Manager-2019-09-08_21-01-00" part of the non-commented line is the name of the actual backup being restored.

The "/vmfs/volumes/Alpha" part is the folder containing the original VM. (or, at least, the folder you want to restore to...)

If you are restoring to the original VM, delete the original VM first:

rm -R /vmfs/volumes/Alpha/Manager

(do it in the GUI...)

Restore the VM:

./ghettoVCB-restore.sh -c vms_to_restore

Customization

Set up a cron job

I'll have to properly detail this yet...

Meanwhile: Add cron Job to VMware ESX/ESXi

Here's an ugly example based on how I got it working here...

  • /bin/kill $(cat /var/run/crond.pid)
    • This stops cron
  • vi /var/spool/cron/crontabs/root
    • Add the following at the bottom:
    • 1    2    *   *   *   "/vmfs/volumes/Alpha/Utility_Room/ghettoVCB/ghettoVCB.sh" -m "Manager" -g "/vmfs/volumes/Alpha/Utility_Room/ghettoVCB/ghettoVCB.conf"
  • /usr/lib/vmware/busybox/bin/busybox crond
    • This starts cron back up
  • vi /etc/rc.local.d/local.sh
    • The following lines added BEFORE the exit 0 line tell ESXi to do the modification to crontab at boot time:
    • /bin/kill $(cat /var/run/crond.pid)
    • /bin/echo '1    2    *   *   *   "/vmfs/volumes/Alpha/Utility_Room/ghettoVCB/ghettoVCB.sh" -g "/vmfs/volumes/Alpha/Utility_Room/ghettoVCB/ghettoVCB.conf" -m "Manager"' >> /var/spool/cron/crontabs/root
    • /usr/lib/vmware/busybox/bin/busybox crond
  • /sbin/auto-backup.sh
    • Ensures that the changes to local.sh get written back to the boot thumbdrive.


Simplifying manual backups

cd /vmfs/volumes/Alpha/Utility_Room/ghettoVCB/

for VMName in "$@"
do
echo "###############################"
echo "#  Backing up "$VMName
echo "###############################"
echo
/vmfs/volumes/Alpha/Utility_Room/ghettoVCB/ghettoVCB.sh \
   -g /vmfs/volumes/Alpha/Utility_Room/ghettoVCB/ghettoVCB.conf \
   -m $VMName
echo
echo "###############################"
echo "# "$VMName" is backed up"
echo "###############################"
done

Then you can do fun things like:

./backup.sh Manager WebServer Automation Download

& all the VMs will get backed up.

(Now find out how to put it directly in the execution path...)

Tricks with ghettoVCB backups

Cloning preconfigured VMs

Yes, this IS a good way to duplicate preconfigured VMs.

Moving & copying VMs to another physical machine

Duplicate the backup onto the destination machine.

  • On the Source machine:
    • change to the folder containing the backups of interest:
      • cd /vmfs/volumes/Beta/BACKUPS/Manager/
    • Create an archive of the backup set required:
      • tar c -z -f Manager.tgz Manager-2019-09-08_21-01-00
  • On the Destination machine:
    • change to the backups folder:
      • cd /vmfs/volumes/Beta/BACKUPS/
    • Create a destination:
      • mkdir Manager/
  • Move the archive to the backups folder on the destination machine (transport method of your choice...)
    • Enter the destination backup folder:
      • cd Manager
    • Extract the archive:
      • tar x -z -f Manager.tgz
    • Now you can simply restore it as normal.

Still to be done

  • Look into partial backups. i.e.: select specific drives on a per-VM basis

Backing up (or copying/moving) the Backups

This is a Work In Progress

  • Over the network
    • Using the web interface
      1. Sign into the machine with a web browser
      2. Select Storage
      3. Click "Datastore browser"
      4. Navigate to the backups
      5. Download them
    • Using NFS
      • ghettoVCB has this built-in, but you'll need an NFS server available full time.
  • Using a hot-swap drive
    • If your server has hot-swap bays, it's a simple matter of copying your backups to a datastore located on one of the hot-swappable drives &, well, hot-swapping it.
  • Using an external drive
    • Careful... This is a good way to mess up your server
      • Start here: USB Devices as VMFS Datastore in vSphere ESXi 6.0
      • An example sequence of commands used here:
        • /etc/init.d/usbarbitrator stop
        • ls /dev/disks/
          • My external drive (a 1TB WD My Passport Ultra)shows up as mpx.vmhba36
        • partedUtil mklabel /dev/disks/mpx.vmhba36\:C0\:T0\:L0 gpt
        • partedUtil setptbl /dev/disks/mpx.vmhba36\:C0\:T0\:L0 gpt "1 2048 1953455804 AA31E02A400F11DB9590000C2911D1B8 0"
        • vmkfstools -C vmfs5 -S VMFS-Backups /dev/disks/mpx.vmhba36\:C0\:T0\:L0:1
        • cp -R /vmfs/volumes/Beta/BACKUPS/* /vmfs/volumes/VMFS-Backups/

Reference Links

Using vi