Skip to main content

BAFM

  • Home
  • Privacy Policy
  • Projects
  • About Me

Tag: Metadata

XenServer – Automation Metdata backups

June 5, 2012June 21, 2013 Christian Leave a comment

Well, we had some issues with XenServers “automated” metadata backup, so I decided – with the help of one of our consultants – to automate it on our own to an external target.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
; html-script: false crayon-selected ]#!/bin/bash
 
# Crontab entry for each server:
# 02 5 * * * root /usr/local/sbin/xen-pool-backup.sh
 
# Get the pool name
POOL_NAME="$( xe pool-list | grep name-label | awk '{ print $4 }' )"
HOST_UUID="$( xe host-list hostname=`hostname` | grep "uuid ( RO)" |
  awk '{ print $5 }' )"
 
DAILY_GENERATIONS=7
WEEKLY_GENERATIONS=4
 
NFS_MOUNT="nfs.home.barfoo.org:/srv/xenbackup"
NFS_LOCAL="/tmp/backup-mount/$POOL_NAME"
 
# Figure out if we're the pool master
POOL_MASTER="$( xe pool-list | grep master | awk '{ print $4 }' )"
 
if [ "$POOL_MASTER" == "$HOST_UUID" ] ; then
  # Only the pool master should backup the pool database, as this is the only
  # one who has a authoritive pool database
 
  # Create the necessary directory and mount the NFS volume
  mkdir -p ${NFS_LOCAL%/*}
  mount -t nfs $NFS_MOUNT ${NFS_LOCAL%/*}
  mkdir -p $NFS_LOCAL
 
  if [ -f $NFS_LOCAL/daily.$DAILY_GENERATIONS.gz ]; then
    rm -f $NFS_LOCAL/daily.$DAILY_GENERATIONS.gz
  fi
 
  OLD_DAILY="$( echo "scale=0; $DAILY_GENERATIONS - 1" | bc )"
 
  for OLD in $( seq $OLD_DAILY -1 1 ); do
    if [ -f $NFS_LOCAL/daily.$OLD.gz ] ; then
      NEW="$( echo "scale=0; $OLD+1" | bc )"
 
      # Save the time stamp somewhere
      touch $NFS_LOCAL/.timestamp -r $NFS_LOCAL/daily.$OLD.gz
      mv $NFS_LOCAL/daily.$OLD.gz $NFS_LOCAL/daily.$NEW.gz
 
      # Restore the date
      touch $NFS_LOCAL/daily.$NEW.gz -r $NFS_LOCAL/.timestamp
    fi
  done
 
  [ -f $NFS_LOCAL/daily.0.gz ] && mv $NFS_LOCAL/daily.0.gz
    $NFS_LOCAL/daily.1.gz
  xe pool-dump-database file-name=$NFS_LOCAL/daily.0
  gzip -9 $NFS_LOCAL/daily.0
 
  [ -f $NFS_LOCAL/.timestamp ] && rm $NFS_LOCAL/.timestamp
  umount ${NFS_LOCAL%/*}
 
  rm -rf ${NFS_LOCAL%/*}
fi

With that, I have at least a daily backup – and in combination with our daily TSM backup, I have at least month long history of metadata backups.

Random Quote

I will not be concerned at other men’s not knowing me;I will be concerned at my own want of ability.

— Confucius
June 2025
S M T W T F S
1234567
891011121314
15161718192021
22232425262728
2930  
« Mar    

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© Christian Heim and christian.weblog.heimdaheim.de, 2018. Unauthorized use and/or duplication of this material without express and written permission from this site’s author and/or owner is strictly prohibited. Excerpts and links may be used, provided that full and clear credit is given to Christian Heim and BAFM with appropriate and specific direction to the original content. Theme by Colorlib Powered by WordPress