In
the previous article about VMware VCB, I wrote about full backups to NFS shares. For completeness, I decided to write another one dedicated to backups to Samba or Windows shares.
The idea of backup is the same. Let's have a Samba server available at IP address 192.168.1.1. The exported directory for backups is backup-smb and the user which has write access to this share is backup.
Before we will be able to continue we need to allow
smbclient to access Samba server. You can perform it from VI client or directly from ESX service console via
esxcfg-firewall command. First, let's check if
smbclient is allowed:
esxcfg-firewall -q smbClient
The output of command should be by default:
Service smbClient is blocked.
To reconfigure ESX firewall to allow
smbclient access use the next command:
esxcfg-firewall -e smbClient
Now, you should be able to browse the server (the command asks for user's password first):
smbclient -L 192.168.1.1 -U backup
The example command output follows (Samba server on SLES10):
Domain=[NAS] OS=[Unix] Server=[Samba 3.0.28-0.2-1625-SUSE-CODE10]
Sharename Type Comment
--------- ---- -------
profiles Disk Network Profiles Service
backup-smb Disk
IPC$ IPC IPC Service (Samba 3.0.28-0.2-1625-SUSE-CODE10)
Domain=[NAS] OS=[Unix] Server=[Samba 3.0.28-0.2-1625-SUSE-CODE10]
Now, we are ready to create a simple backup script:
#!/bin/sh
BACKUP_SERVER="192.168.1.1"
BACKUP_USER="backup"
BACKUP_PASS="backup"
SMB_SHARE="backup-smb"
MOUNT_DIR="/backup"
[ -d $MOUNT_DIR ] || mkdir -p "$MOUNT_DIR" || exit 1
VM_BACKUP="`vcbVmName -s any: | grep name: | cut -d':' -f2`"
if [ ! -z "$VM_BACKUP" ]; then
smbmount //${BACKUP_SERVER}/$SMB_SHARE $MOUNT_DIR \
-o username=${BACKUP_USER},password=$BACKUP_PASS || exit 1
for VM in $VM_BACKUP; do
vcbMounter -a name:$VM -r $MOUNT_DIR/$VM
done
umount $MOUNT_DIR
fi
exit 0
It is simple, isn't it? The code is almost the same as for
backups over NFS. We added variables defining our Samba user and his password. The
mount command was exchanged with
smbmount which is CLI Samba client. If you insist on using the
mount command replace the line mounting the
backup-smb share with line:
mount -t smbfs //${BACKUP_SERVER}/$SMB_SHARE $MOUNT_DIR \
-o username=${BACKUP_USER},password=$BACKUP_PASS || exit 1
That's all. In such simple backup scenarios I prefer NFS usage because it is simple to set and provides higher throughput than SMB protocol. On the other hand, SMB protocol provides basic authentication mechanism (if you don't disable it).