User Tools

Site Tools


backup_vmware

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
backup_vmware [2015/05/05 16:44] herwarthbackup_vmware [2015/05/05 17:44] (current) herwarth
Line 1: Line 1:
 ======How to make backups in VMware using ghettoVCB.sh and crontab====== ======How to make backups in VMware using ghettoVCB.sh and crontab======
 =====Install ghettoVCB===== =====Install ghettoVCB=====
 +Download latest files from github:
 +[[https://github.com/lamw/ghettoVCB]]
 +Put the files on a datastore. I use datastore backup (/vmfs/volumes/backup), which is an NFS mount.
 +I have put the original scripts in /vmfs/volumes/backup/bin. I have create my own cron script to put the backup files in the necessary directories.
 +
 +From download machine:
 +  scp ghettoVCB-master.zip root@supermicro1.mngt.bh.helux.nl:/vmfs/volumes/backup
 +From hypervisor:
 +  cd /vmfs/volumes/backup
 +  unzip ghettoVCB-master.zip
 +  mv ghettoVCB-master bin
 +  mkdir log
 +  mkdir data
 +  mkdir conf
 +
 +<code - /vmfs/volumes/backup/cron-ghettoVCB.sh>
 +#!/bin/sh
 +BACKUPDIR=/vmfs/volumes/backup
 +BINDIR=$BACKUPDIR/bin
 +CONFDIR=$BACKUPDIR/conf
 +LOGDIR=$BACKUPDIR/log
 +DATE=$(date +%d-%m-%Y-%H-%M)
 +HOSTNAME=$(hostname)
 +
 +case $(hostname -d) in
 +  mngt.bh.helux.nl) DOMAIN=bh ;;
 +  mngt.rtd.helux.nl) DOMAIN=rtd ;;
 +  mngt.ams.helux.nl) DOMAIN=ams ;;
 +  *) DOMAIN=unknown ;;
 +esac
 +
 +$BINDIR/ghettoVCB.sh -a -g $CONFDIR/ghettoVCB-$DOMAIN.conf -l $LOGDIR/$HOSTNAME-$DATE.log >/dev/null 2>&1
 +
 +exit 0
 +</code>
 +
 =====Configure ghettoVCB===== =====Configure ghettoVCB=====
 +I use different configs for each datacenter. I have hypervisors in 3 datacenters.
 +
 +<code - /vmfs/volumes/backup/conf/ghettoVCB-ams.conf>
 +VM_BACKUP_VOLUME=/vmfs/volumes/backup/data/amsterdam
 +DISK_BACKUP_FORMAT=thin
 +VM_BACKUP_ROTATION_COUNT=1
 +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=1
 +ENABLE_NON_PERSISTENT_NFS=0
 +UNMOUNT_NFS=0
 +NFS_SERVER=172.30.0.195
 +NFS_VERSION=nfs
 +NFS_MOUNT=/nfsshare
 +NFS_LOCAL_NAME=nfs_storage_backup
 +NFS_VM_BACKUP_DIR=mybackups
 +SNAPSHOT_TIMEOUT=15
 +EMAIL_LOG=0
 +EMAIL_SERVER=auroa.primp-industries.com
 +EMAIL_SERVER_PORT=25
 +EMAIL_DELAY_INTERVAL=1
 +EMAIL_TO=auroa@primp-industries.com
 +EMAIL_FROM=root@ghettoVCB
 +WORKDIR_DEBUG=0
 +VM_SHUTDOWN_ORDER=
 +VM_STARTUP_ORDER=
 +</code>
 +<code - /vmfs/volumes/backup/conf/ghettoVCB-bh.conf>
 +VM_BACKUP_VOLUME=/vmfs/volumes/backup/data/bergschenhoek
 +DISK_BACKUP_FORMAT=thin
 +VM_BACKUP_ROTATION_COUNT=1
 +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=1
 +ENABLE_NON_PERSISTENT_NFS=0
 +UNMOUNT_NFS=0
 +NFS_SERVER=172.30.0.195
 +NFS_VERSION=nfs
 +NFS_MOUNT=/nfsshare
 +NFS_LOCAL_NAME=nfs_storage_backup
 +NFS_VM_BACKUP_DIR=mybackups
 +SNAPSHOT_TIMEOUT=15
 +EMAIL_LOG=0
 +EMAIL_SERVER=auroa.primp-industries.com
 +EMAIL_SERVER_PORT=25
 +EMAIL_DELAY_INTERVAL=1
 +EMAIL_TO=auroa@primp-industries.com
 +EMAIL_FROM=root@ghettoVCB
 +WORKDIR_DEBUG=0
 +VM_SHUTDOWN_ORDER=
 +VM_STARTUP_ORDER=
 +</code>
 +<code - /vmfs/volumes/backup/conf/ghettoVCB-rtd.conf>
 +VM_BACKUP_VOLUME=/vmfs/volumes/backup/data/rotterdam
 +DISK_BACKUP_FORMAT=thin
 +VM_BACKUP_ROTATION_COUNT=1
 +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=1
 +ENABLE_NON_PERSISTENT_NFS=0
 +UNMOUNT_NFS=0
 +NFS_SERVER=172.30.0.195
 +NFS_VERSION=nfs
 +NFS_MOUNT=/nfsshare
 +NFS_LOCAL_NAME=nfs_storage_backup
 +NFS_VM_BACKUP_DIR=mybackups
 +SNAPSHOT_TIMEOUT=15
 +EMAIL_LOG=0
 +EMAIL_SERVER=auroa.primp-industries.com
 +EMAIL_SERVER_PORT=25
 +EMAIL_DELAY_INTERVAL=1
 +EMAIL_TO=auroa@primp-industries.com
 +EMAIL_FROM=root@ghettoVCB
 +WORKDIR_DEBUG=0
 +VM_SHUTDOWN_ORDER=
 +VM_STARTUP_ORDER=
 +</code>
 +
 =====Configure crontab===== =====Configure crontab=====
 +Add the following on each ESXi hypervisor. The notation of the crontab is as follows:
 +  #min hour day mon dow command
 +
 +using the following config it means. run on 1:00 on sunday (day 0)
 +
 +<code - /etc/rc.local.d/local.sh>
 +.
 +.
 +/bin/kill $(cat /var/run/crond.pid)
 +/bin/echo "   1    *       /vmfs/volumes/backup/cron-ghettoVCB.sh" >> /var/spool/cron/crontabs/root
 +crond
 +exit 0
 +</code>
 +
 +after that run it for 1 time only!
 +
 +  /etc/rc.local.d/local.sh
 +
 +make it persistent
 +
 +  /sbin/auto-backup.sh
 +
 +=====Use Bacula to backup the NFS share=====
 +We only backup vms backupped with status OK. So I use a script before I run the Bacula job.
 +This script is the same NFS share on Linux as a datastore on the hypervisor. In this situation the NFS share is mounted on /mnt/synology/volume1/vmware/backup on the Linux machine we are going to backup using Bacula.
 +
 +<code - run-before-bacula.sh>
 +#!/bin/bash
 +BACKUPDIR=/mnt/synology/volume1/vmware/backup
 +STATUSOK=STATUS.ok
 +STATUSWARN=STATUS.warn
 +TEMPDIR=$BACKUPDIR/temp
 +
 +case $1 in
 +  bh) DATADIR=$BACKUPDIR/data/bergschenhoek ;;
 +  rtd) DATADIR=$BACKUPDIR/data/rotterdam ;;
 +  ams) DATADIR=$BACKUPDIR/data/amsterdam ;;
 +  *) echo "usage $0 <bh|rtd|ams>"
 +     exit 1 ;;
 +esac
 + 
 +rm -rf $TEMPDIR/*
 +
 +for fulldir in $(find $DATADIR -name $STATUSOK -exec dirname {} \; -o -name $STATUSWARN -exec dirname {} \; ); do
 +  DIR=$(basename $fulldir)
 +  VMNAME=$(echo $fulldir | sed  "s|$DATADIR||" | cut -d'/' -f2)
 +  if [ ! -d $TEMPDIR/$VMNAME ]; then
 +    mkdir $TEMPDIR/$VMNAME
 +  fi
 +  mv $fulldir $TEMPDIR/$VMNAME
 +done
 +
 +rm -rf $DATADIR/*
 +mv $TEMPDIR/* $DATADIR
 +</code>
 +
  
-{{tag>other}}+{{tag>vmware}}
  
backup_vmware.1430844291.txt.gz · Last modified: by herwarth