Open main menu

OpenVZ Virtuozzo Containers Wiki β

Editing Ploop/Backup

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
 
[[File:Ploop-backup.png|300px|right|thumb|How backup via snapshot is done]]
 
[[File:Ploop-backup.png|300px|right|thumb|How backup via snapshot is done]]
This article explains how to do consistent backups for [[ploop]] containers, using ploop snapshot feature.
+
This article explains how to do consistent file-based backups for [[ploop]] containers, using ploop snapshot feature.
  
== Backup types ==
+
== Types of backup ==
 
There are two ways of doing backups, both have their pros and cons.
 
There are two ways of doing backups, both have their pros and cons.
  
Line 29: Line 29:
 
|-
 
|-
 
|| Compatible with pre-ploop backups
 
|| 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}}
+
| {{No}} || {{Yes}}
 
|-
 
|-
 
|| Restore individual files
 
|| Restore individual files
Line 35: Line 35:
 
|}
 
|}
  
== Image-based backup ==
+
== Image-based backups ==
  
 
Assuming you have a running container identified by <code>$CTID</code>. The following needs to be done:
 
Assuming you have a running container identified by <code>$CTID</code>. The following needs to be done:
Line 42: Line 42:
 
# Known snapshot ID
 
# Known snapshot ID
 
ID=$(uuidgen)
 
ID=$(uuidgen)
VE_PRIVATE=$(vzlist -H -o private $CTID)
+
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
 
# Take a snapshot without suspending a CT and saving its config
Line 53: Line 53:
 
# Delete (merge) the snapshot
 
# Delete (merge) the snapshot
 
vzctl snapshot-delete $CTID --id $ID
 
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>
 
</source>
  
Line 116: Line 75:
 
# Perform a backup using your favorite backup tool
 
# Perform a backup using your favorite backup tool
 
# (tar is just an example)
 
# (tar is just an example)
tar cf backup.tar $MNTDIR
+
tar cf backup.tar.xz $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
 
# Unmount the snapshot
Line 131: Line 86:
 
== See also ==
 
== See also ==
  
* [[Ploop]]
 
 
* [[Man/vzctl.8#Snapshotting|vzctl(8), section Snapshotting]].
 
* [[Man/vzctl.8#Snapshotting|vzctl(8), section Snapshotting]].
  
[[Category: Storage]]
+
[[Category:ploop]]
[[Category: HOWTO]]
+
[[Category:HOWTO]]

Please note that all contributions to OpenVZ Virtuozzo Containers Wiki may be edited, altered, or removed by other contributors. If you don't want your writing to be edited mercilessly, then don't submit it here.
If you are going to add external links to an article, read the External links policy first!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)