Changes

Jump to: navigation, search

Ploop/Backup

1,231 bytes added, 10:10, 27 September 2013
Image-based backup: I added a new script.
# 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=$(VEID=$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
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*" | head -n-4 )
 
echo "BACKUP FINISHED."
</source>
2
edits

Navigation menu