Difference between revisions of "Ploop/Backup"
(add image-based backup and comparison) |
|||
(8 intermediate revisions by 3 users not shown) | |||
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 | + | This article explains how to do consistent backups for [[ploop]] containers, using ploop snapshot feature. |
− | == | + | == Backup types == |
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 | ||
− | | {{No}} || {{Yes}} | + | | {{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 | || Restore individual files | ||
Line 35: | Line 35: | ||
|} | |} | ||
− | == Image-based | + | == Image-based backup == |
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=$( | + | VE_PRIVATE=$(vzlist -H -o private $CTID) |
# 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 75: | Line 116: | ||
# 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.xz $MNTDIR | + | 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 | # Unmount the snapshot | ||
Line 86: | Line 131: | ||
== See also == | == See also == | ||
+ | * [[Ploop]] | ||
* [[Man/vzctl.8#Snapshotting|vzctl(8), section Snapshotting]]. | * [[Man/vzctl.8#Snapshotting|vzctl(8), section Snapshotting]]. | ||
− | [[Category: | + | [[Category: Storage]] |
− | [[Category:HOWTO]] | + | [[Category: HOWTO]] |
Latest revision as of 16:46, 6 September 2015
This article explains how to do consistent backups for ploop containers, using ploop snapshot feature.
Backup types[edit]
There are two ways of doing backups, both have their pros and cons.
- When doing an image backup, one copies ploop image files directly. There can be only one big file, or maybe a few relatively big files. Copying a few big files (rather than a lot of small files) is faster because there's not too much metadata (file info) to be copied). Also, filesystem properties are fully preserving (since images containing the filesystem are copied).
- When doing a file backup, one copies individual container' files. This is more suitable if you want selective backups (such as only some directories/files).
The following table summarizes pros and cons of both approaches.
Characteristic | Image | File |
---|---|---|
Incremental backups | Yes | Yes/No* |
Selective backups | No | Yes |
Faster full backup and restore | Yes | No |
Preserve filesystem properties | Yes | No |
Compatible with pre-ploop backups | Yes/No* | Yes |
Restore individual files | Yes | Yes |
Image-based backup[edit]
Assuming you have a running container identified by $CTID
. The following needs to be done:
# 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/* /backup/destination
# Delete (merge) the snapshot
vzctl snapshot-delete $CTID --id $ID
The following script implements the commands above and allows - when stored as vzbackup
- to backup your container by executing the script in the following way:
./vzbackup 101 /backup/destination/
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 head -n-4
to the number of backups you would like to keep.
#!/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."
File-based backup[edit]
Assuming you have a running container identified by $CTID
. The following needs to be done:
# Known snapshot ID
ID=$(uuidgen)
# Directory used to mount a snapshot
MNTDIR=./mnt
mkdir $MNTDIR
# Take a snapshot without suspending a CT and saving its config
vzctl snapshot $CTID --id $ID --skip-suspend --skip-config
# Mount the snapshot taken
vzctl snapshot-mount $CTID --id $ID --target $MNTDIR
# 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
vzctl snapshot-umount $CTID --id $ID
# Delete (merge) the snapshot
vzctl snapshot-delete $CTID --id $ID