Difference between revisions of "ESXi - ghettoVCB"
(10 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | [https://github.com/lamw/ghettoVCB ghettoVCB on GitHub] | ||
+ | |||
==Installation== | ==Installation== | ||
===Install ghettoVCB=== | ===Install ghettoVCB=== | ||
Line 27: | Line 29: | ||
===Create a Backup folder on the datastore=== | ===Create a Backup folder on the datastore=== | ||
− | <code>mkdir "/vmfs/volumes/ | + | |
+ | '''Not needed if your datastores are set up in the "standard" way...''' | ||
+ | |||
+ | <s><code>mkdir "/vmfs/volumes/Backups"</code></s> | ||
ghettoVCB will create subfolders for each VM you backup inside this folder. | ghettoVCB will create subfolders for each VM you backup inside this folder. | ||
Line 148: | Line 153: | ||
===Simplifying manual backups=== | ===Simplifying manual backups=== | ||
+ | |||
+ | '''NOTE:''' Need to do some sort of error handling. ATM, if you try to backup a VM that doesn't exist, it fails silently. | ||
<code>cd /vmfs/volumes/Admin/Utilities/ghettoVCB/</code> | <code>cd /vmfs/volumes/Admin/Utilities/ghettoVCB/</code> | ||
Line 244: | Line 251: | ||
****<code>./ghettoVCB.sh -g ./CloneMe.conf -m CloneMe-Mint-19.3</code> | ****<code>./ghettoVCB.sh -g ./CloneMe.conf -m CloneMe-Mint-19.3</code> | ||
− | *Need a way to tell <code>clone.sh</code> | + | *Need a way to tell <code>clone.sh</code> which '''CloneMe''' to use... |
− | * | + | **This particular rabbit hole has forced the realisation that '''sh''' as implemented in ESXi is a poor substitute for bash. |
+ | **The [[GhettoVCB - clone.sh BASH Script|script]] to provide a menu of available '''CloneMe'''s in bash is quite elegant. | ||
+ | **The [[GhettoVCB - clone.sh Script|script]] to do the same in ESXis '''sh''' is a fugly mess of hard-coded information. | ||
+ | *&, of course, where to actually put the clone. | ||
+ | **(see comments just above about shell implementation... :( ) | ||
===Simplifying Restoration of a Backup=== | ===Simplifying Restoration of a Backup=== | ||
Line 291: | Line 302: | ||
**Using NFS | **Using NFS | ||
***ghettoVCB has this built-in, but you'll need an NFS server available full time. | ***ghettoVCB has this built-in, but you'll need an NFS server available full time. | ||
+ | **<span style="color:green">'''Using SCP'''</span> | ||
+ | ***First things first... Enable outgoing SCP on the host. (SSH Client) | ||
+ | ****[https://4sysops.com/archives/how-to-open-and-close-firewall-ports-on-vmware-esxi-hosts/ How to Open and Close Firewall Ports on vmWare ESXi Hosts] | ||
+ | ***Next, change to your backups folder. | ||
+ | ****<code>cd /vmfs/volumes/Backup</code> | ||
+ | ***Then, SCP your backup to another machine. | ||
+ | ****<code>scp -r Backup user@machine:destination</code> | ||
*Using a hot-swap drive | *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. | **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. | ||
Line 321: | Line 339: | ||
*[https://www.cs.colostate.edu/helpdocs/vi.html Basic vi Commands] (CSU) | *[https://www.cs.colostate.edu/helpdocs/vi.html Basic vi Commands] (CSU) | ||
*[https://www.ccsf.edu/Pub/Fac/vi.html UNIX: vi Editor] (City College of SF) | *[https://www.ccsf.edu/Pub/Fac/vi.html UNIX: vi Editor] (City College of SF) | ||
− | * | + | *VI Text Editor with Commands: Linux/Unix Tutorial (Guru99) |
+ | ** Link removed because Guru99 apparently no longer wants traffic |
Latest revision as of 00:46, 23 August 2023
Contents
Installation
Install ghettoVCB
- SSH (as root) into the machine
- Create a Utilities folder on an existing datastore
mkdir "/vmfs/volumes/Admin/Utilities/"
- (This exact location is specific to my testbed server...)
- Remember this location... It'll be very useful...
- switch to this folder
cd "/vmfs/volumes/Admin/Utilities/"
- 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)
- Unpack & rename ghettoVCB
unzip ghettoVCB.zip
mv ghettoVCB-master ghettoVCB
- switch to the new folder
cd ghettoVCB
- Install it!
esxcli software vib install -v "/vmfs/volumes/Admin/Utilities/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
Not needed if your datastores are set up in the "standard" way...
mkdir "/vmfs/volumes/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/Admin/Utilities/ghettoVCB/ghettoVCB.sh" -m "Manager" -g "/vmfs/volumes/Admin/Utilities/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 tocrontab
at boot time: /bin/kill $(cat /var/run/crond.pid)
/bin/echo '1 2 * * * "/vmfs/volumes/Admin/Utilities/ghettoVCB/ghettoVCB.sh" -g "/vmfs/volumes/Admin/Utilities/ghettoVCB/ghettoVCB.conf" -m "Manager"' >> /var/spool/cron/crontabs/root
/usr/lib/vmware/busybox/bin/busybox crond
- The following lines added BEFORE the
/sbin/auto-backup.sh
- Ensures that the changes to
local.sh
get written back to the boot thumbdrive.
- Ensures that the changes to
Simplifying manual backups
NOTE: Need to do some sort of error handling. ATM, if you try to backup a VM that doesn't exist, it fails silently.
cd /vmfs/volumes/Admin/Utilities/ghettoVCB/
vi backup.sh
#!/bin/sh export PATH=/bin:/sbin for VMName in "$@" do echo "###############################" echo "# Backing up "$VMName echo "###############################" echo logger "ghettoVCB/backup.sh is backing up "$VMName"." /vmfs/volumes/Admin/Utilities/ghettoVCB/ghettoVCB.sh \ -g /vmfs/volumes/Admin/Utilities/ghettoVCB/ghettoVCB.conf \ -m $VMName logger "ghettoVCB/backup.sh is finished backing up "$VMName"." echo echo "###############################" echo "# "$VMName" is backed up" echo "###############################" done logger "ghettoVCB/backup.sh finished"
chmod +x backup.sh
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...)
Running a backup remotely
Note: You'll need to have SSHed into the server previously from the machine you want to run this command from. (SSH is a strange beast... It REALLY wants to set up stuff on your local machine for verification. Whoda Thunkit)
ssh root@ESXiServer "/vmfs/volumes/Admin/Utilities/ghettoVCB/backup.sh VMname"
Simplifying Clone Deployment
cd /vmfs/volumes/Admin/Utilities/ghettoVCB/
vi clone.sh
#!/bin/sh export PATH=/bin:/sbin for VMName in "$@" do echo "###############################" echo "# Creating "$VMName echo "###############################" echo logger "ghettoVCB/clone.sh is creating "$VMName" from CloneMe." echo "/vmfs/volumes/Admin/CloneMe/CloneMe-Mint-19.3/CloneMe-Mint-19.3-0;/vmfs/volumes/Admin;1;"$VMName > CloneIt /vmfs/volumes/Admin/Utilities/ghettoVCB/ghettoVCB-restore.sh -c CloneIt logger "ghettoVCB/clone.sh "$VMName" finished" echo echo "###############################" echo "# "$VMName" is created" echo "###############################" done
chmod +x clone.sh
Then you can do fun things like:
./clone.sh Manager WebServer Automation Download
& all the VMs will be created as clones of CloneMe.
Thoughts
- Need to create a CloneMe creator script.
- Multiple CloneMes would be good...
- Duplicate
ghetoVCB.conf
toCloneMe.conf
- Add in,
VM_BACKUP_VOLUME="/vmfs/volumes/Admin/CloneMe"
VM_BACKUP_DIR_NAMING_CONVENTION="0"
- Then:
./ghettoVCB.sh -g ./CloneMe.conf -m CloneMe-Mint-19.3
- Add in,
- Need a way to tell
clone.sh
which CloneMe to use... - &, of course, where to actually put the clone.
- (see comments just above about shell implementation... :( )
Simplifying Restoration of a Backup
Coming SoonTM...
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
- change to the folder containing the backups of interest:
- On the Destination machine:
- change to the backups folder:
cd /vmfs/volumes/Beta/BACKUPS/
- Create a destination:
mkdir Manager/
- change to the backups folder:
- 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.
- Enter the destination backup folder:
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
- Sign into the machine with a web browser
- Select Storage
- Click "Datastore browser"
- Navigate to the backups
- Download them
- Using NFS
- ghettoVCB has this built-in, but you'll need an NFS server available full time.
- Using SCP
- First things first... Enable outgoing SCP on the host. (SSH Client)
- Next, change to your backups folder.
cd /vmfs/volumes/Backup
- Then, SCP your backup to another machine.
scp -r Backup user@machine:destination
- Using the web interface
- 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.0An example sequence of commands used here:/etc/init.d/usbarbitrator stopls /dev/disks/My external drive (a 1TB WD My Passport Ultra)shows up asmpx.vmhba36
partedUtil mklabel /dev/disks/mpx.vmhba36\:C0\:T0\:L0 gptpartedUtil 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:1cp -R /vmfs/volumes/Beta/BACKUPS/* /vmfs/volumes/VMFS-Backups/
- Careful... This is a good way to mess up your server
Reference Links
- The original package on GitHub
- Documentation for ghettoVCB
- Documentation for ghettoVCB-restore
- VMTN ghettoVCB discussion group
- Backing up VMware ESXi VMs with ghettoVCB
Using vi
- Basic vi Commands (CSU)
- UNIX: vi Editor (City College of SF)
- VI Text Editor with Commands: Linux/Unix Tutorial (Guru99)
- Link removed because Guru99 apparently no longer wants traffic