Open main menu

OpenVZ Virtuozzo Containers Wiki β

Changes

Ploop/Backup

1,412 bytes added, 16:46, 6 September 2015
no edit summary
[[File:Ploop-backup.png|300px|right|thumb|How backup via snapshot is done]]
This article explains how to do consistent file-based backups for [[ploop]] containers, using ploop snapshot feature.
== Backup types ==
|-
|| Compatible with pre-ploop backups
| {{Yes-No}}{{H:title|It's always possible to create a new, same-size ploop device and then restore the files into the mounted ploop partition|<sup>*</sup>}} || {{Yes}}
|-
|| Restore individual files
# Known snapshot ID
ID=$(uuidgen)
VE_PRIVATE=$(VEID=vzlist -H -o private $CTID; source /etc/vz/vz.conf; source /etc/vz/conf/$CTID.conf; echo $VE_PRIVATE)
# Take a snapshot without suspending a CT and saving its config
# Delete (merge) the snapshot
vzctl snapshot-delete $CTID --id $ID
</source>
 
The following script implements the commands above and allows - when stored as <code>vzbackup</code> - to backup your container by executing the script in the following way:
 
<code>./vzbackup 101 /backup/destination/</code>
 
The script removes older backups and keeps only the latest four backups. You can change the number of backups kept by changing the four in <code>head -n-4</code> to the number of backups you would like to keep.
 
<source lang="bash">
#!/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 --skip-suspend --skip-config
# Perform a backup using your favorite backup tool
# (cp is just an example)
cp $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."
</source>
# Perform a backup using your favorite backup tool
# (tar is just an example)
tar cf backup.tar $MNTDIR # tar with compression examples, see man page of tar for more options# tar cfJ backup.tar.xz $MNTDIR# tar cfz backup.tar.gz $MNTDIR
# Unmount the snapshot
== See also ==
* [[Ploop]]
* [[Man/vzctl.8#Snapshotting|vzctl(8), section Snapshotting]].
[[Category:ploopStorage]][[Category:HOWTO]]
14
edits