I know there was a forum here for user created scripts and whatnot but I can no longer find it...but I wanted to share a script that a colleague and I put together to back up the contents of the /etc folder prior to any upgrades, updates, etc. I wanted to get this scripted because a while back while updating some hosts to 3.0.2...something went wonky and one of the hosts ended up with a corrupted esx.conf file that took VMware Support to help us figure out what the issue was. I did some searching today here on the forums about what to backup prior to an upgrade and I saw that most of the "gurus" here said they felt that backing up /etc was the most important. The script we came up with actually relies on 3 files total for it to work correctly.
First, in the home directory of the logged in user, create a file called .netrc. Open this file in an editor and add the following:
machine <IP address of the ftp server>
login <username for the ftp server>
password <password for the ftp server>
Save the file and chmod it to 600 to keep others from being able to access the file.
Next, a file called autoftp was created and chmod'd to be executable. It contains the following:
open x.x.x.x <opens an ftp session to the ftp server>
cd <Folder for the backups>
bin <changes to binary mode>
prompt <disables interactive prompting>
lcd <file location>
mput *.tgz <transfers the tar gzip'd archive the folder on the FTP server>
bye <ends the ftp session>
Finally, a file called esxbackup was created. The file contains the following:
#!/bin/sh
Today="`date +%y%m%d`" <sets a variable called Today that takes today's date and adds the year and month before it>
tar -czvf $HOSTNAME.$Today.tgz etc/ <creates a gzipped tar file of /etc and names it as FQDN and date.tgz>
esxcfg-firewall -allowOutgoing <Disables the firewall>
esxcfg-firewall -allowIncoming
ftp < autoftp <runs ftp using the options found in a file called autoftp>
esxcfg-firewall -BlockIncoming <Enables the firewall>
esxcfg-firewall -BlockOutgoing
If all goes properly, after the script completes, you should be able to check the ftp server and see an archive in the format of full.host.name.<Date>.tgz
I am sure there are alot more elegant scripts out there to handle this, but this works for us and I wanted to share it with you guys.