OpenVZ Forum


Home » General » Support » Container backup (no official info) (Cannot find supprted way to backup containers)
Re: Container backup (no official info) [message #52630 is a reply to message #52532] Wed, 16 November 2016 08:53 Go to previous messageGo to previous message
nebbian is currently offline  nebbian
Messages: 3
Registered: November 2016
Location: Western Australia
Junior Member
I've come across this issue today. Here's how I did it (based on how it was done in previous versions of OpenVZ).

1) Create /usr/local/bin/vzbackup:

#!/bin/bash
if [ -z $1 -o -z $2 ]
then
         echo "Usage: vzbackup CTID BACKUP-PATH"
         exit 1
fi

CTID=$1
FOLDER=$2
BACKUPPATH=$FOLDER/$CTID-$(date +%F_%H_%M)

#create BACKUP-PATH
mkdir -p $BACKUPPATH

# Known snapshot ID
ID=$(uuidgen)
VE_PRIVATE=$(vzlist -H -o private $CTID)

# Take a snapshot without suspending a CT and saving its config
vzctl snapshot $CTID --id $ID

# Perform a backup using your favorite backup tool
# (cp is just an example)
cp -r $VE_PRIVATE/root.hdd/* $BACKUPPATH/

# Delete (merge) the snapshot
vzctl snapshot-delete $CTID --id $ID

# remove old backups
rm -rf $( find $FOLDER -type d -name "$CTID*" -exec ls -d1rt "{}" + | head -n-4  )

echo "BACKUP FINISHED."




2) Run this periodically, passing in the container ID and the backup location, eg:
/usr/local/bin/vzbackup MyCT /backup/openvz/current/

Restoring from this backup

1) Create a new container, eg:
prlctl create Test --vmtype ct --ostemplate centos-7-x86_64

2) Determine the UUID of your new container, eg:
prlctl list -a

3) Copy all files in your latest backup directory to /vz/private/{UUID}/root.hdd/, overwriting all the existing hard disk files in there

4) Start the new container, eg:
prlctl start Test


This appears to be working for me. I'm sure that this isn't the best way to do things, but in my case, at least it's A way to back up my containers. I tried using snapshots, but I don't think that these restore the file system (which seems a bit odd to me).

Maybe it will work for someone. Or maybe I'm deluding myself into thinking that this is a valid backup technique.
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Ploop Backup
Next Topic: application templates
Goto Forum:
  


Current Time: Thu Sep 12 05:18:10 GMT 2024

Total time taken to generate the page: 0.09653 seconds