OpenVZ Forum


Home » General » Support » Need help with script to take back up & restore (openvz, backup & restore)
Need help with script to take back up & restore [message #51822] Wed, 07 January 2015 07:33 Go to next message
hostingraja is currently offline  hostingraja
Messages: 5
Registered: January 2015
Location: Bangalore
Junior Member
first post in openvz! & though i have expr in linux server handing, new to openvz.

I have to take a backup & restore of all the VMs running, basically i am responsible if there is any problem.
As a first step, I am trying to take backup of all VMs and trying to restore it in a new container for testing purpose.

I used github.com/andreasfaerber/vzpbackup/ (this seems to be a best out of all the script i have got for backup from google)
and I have this issues: github.com/andreasfaerber/vzpbackup/issues/6

can someone help me, seems to be a small issue.
As it is a production server and I am new to openvz, bit scared to try anything risky.


Nothing...
Re: Need help with script to take back up & restore [message #51826 is a reply to message #51822] Mon, 12 January 2015 11:06 Go to previous message
hostingraja is currently offline  hostingraja
Messages: 5
Registered: January 2015
Location: Bangalore
Junior Member
As there was some error in the above script, I have searched on Internet and found a script and modified to suit my needs.
I am posting it here, so that it will be helpful for anyone, who needs.

If you have any issues with this script post the problem here, I will try my level best to answer it.

#!/bin/bash
# vzdump-backup.sh
# Backup openVZ containers and container configuration
# This script will suspend containers before doing vzdump
# Use with caution.

backup_parent_dir="/backup"

#Here list the exclude list of CTID to exclude from backup
exlist=("112" "999" "117" "115" "118")

# Cleanup backup directory of old backups
echo "Housekeeping $backup_parent_dir - removing older backups (>14 days)"
find $backup_parent_dir -name "*.tgz" -mtime +14 -print | xargs rm -rf

matched="0"
# Start container backup
for CTID in $( vzlist | awk '{if (NR!=1){print $1}}' )
do
    for e in "${exlist[@]}"
    do
        if [[ "$e" == "$CTID" ]]
        then
            matched="1"
            break ; # Dont take backup
        fi
    done

    if [ $matched = "1" ]  
    then
        CT_name=` vzlist | grep $CTID | awk '{print $5}'` >> /dev/null
        echo "Not Backing up container $CTID - $CT_name"
        matched="0"
        #don't dump
        continue
    fi

    CT_name=` vzlist | grep $CTID | awk '{print $5}'`
    echo "Backing up container $CTID - $CT_name"
    vzdump --compress --dumpdir $backup_parent_dir --tmpdir /data --suspend $CTID
    echo "$CTID - $CT_name backed up - OK!"
done

echo "Backup tasks completed on `date` - showing directory listing"
ls -lsah $backup_parent_dir


Nothing...
Previous Topic: vzctl compact doesnt work
Next Topic: Script to Monitor Email Queue in the Container
Goto Forum:
  


Current Time: Wed Apr 24 23:00:53 GMT 2024

Total time taken to generate the page: 0.01362 seconds