OpenVZ Forum


Home » General » Support » Script to backup groups of vms each day via cron job (Not sure where to put this...)
Re: Script to backup groups of vms each day via cron job [message #50898 is a reply to message #50893] Mon, 25 November 2013 20:00 Go to previous message
nolageek is currently offline  nolageek
Messages: 4
Registered: July 2013
Location: United States
Junior Member
Well, glad to see how helpful the folks here are with fellow openvz users.

Anyway, I was able to get this working and it's run the last few days. I'm posting this because I think it may be helpful for others that are looking for a way to stagger backing up larger numbers of VMs on their host nodes.


#!/bin/sh

# How many days per week do you want to run backups? (starts on monday)
DPW=5
####### END OF CONFIGURATION

if [[ $(date +%u) -gt $DPW ]] ; then
    echo 'Sorry, you cannot run this program today.'
    exit
fi

#figure out how many VMs we have, and figure out how many to backup each day of the week
TOTAL=`/usr/sbin/vzlist -H -o ctid|wc -l`
DAILY=$(($TOTAL/$DPW))

# if Monday, backup first set of $DAILY number of VMs, if tuesday then second set, etc...
DAY="$(date +'%u')"



                NUM2=$(($DAILY * $DAY))
                NUM1=$((($NUM2 - $DAILY)+1))

if [[ ($DAY -eq $DPW)  &&  ($NUM2 -lt $TOTAL)  ]]; then
        NUM2=$TOTAL
fi

# Get list of all VMs, remove leading whitespace, segment them and then back them up
for VM in `/usr/sbin/vzlist -H -o ctid | sed 's/^[ \t]*//' | sed -n "$NUM1,$NUM2 p"`; do /usr/sbin/vzdump --suspend $VM --tmpdir /vz/dump/tmp; done

 
Read Message
Read Message
Read Message
Read Message
Previous Topic: NOHZ: local_softirq_pending 100 - is there something to worry about?
Next Topic: Comparison with Docker
Goto Forum:
  


Current Time: Sun Sep 01 15:46:56 GMT 2024

Total time taken to generate the page: 0.05854 seconds