GitLab de la Mairie de Villejuif

Commit 034aee63 authored by Pedro Amador's avatar Pedro Amador
Browse files

Add snapshot feature

parent b304776f
......@@ -21,9 +21,15 @@ then
echo ""
echo "Error: $msg"
echo "Use:"
echo " backup daily [ctid] [ctid] ... - for daily backup"
echo " backup weekly [ctid] [ctid] ... - for weekly backup"
echo " backup monthly [ctid] [ctid] ... - for monthly backup"
echo " backup daily [snapshot] [ctid] [ctid] ... - for daily backup"
echo " backup weekly [snapshot] [ctid] [ctid] ... - for weekly backup"
echo " backup monthly [snapshot] [ctid] [ctid] ... - for monthly backup"
echo ""
echo " With [snapshot] the script uses 'snapshot' option of vzdump"
echo " - Six 'daily' snapshots (one complete week)"
echo " - Two 'weekly' snapshots (all sundays of month), with one vzdump of all CT's and VM's except exclude list, from last saturnday"
echo " - One 'monthly' (one month), with one vzdump of all CT's and VM's except exclude list, from last 'first monday' of the month"
echo " Use snapshots only with ZFS storage"
echo ""
echo " The [ctid] ... is a list of ID's to exclude in the backup"
exit 1
......@@ -31,6 +37,16 @@ fi
echo `date +"%Y-%m-%d %X"`": backing up $period period "
# Get snapshot
if [[ $2 == 'snapshot' ]]
then
snapshot=true
shift
else
snapshot=false
fi
shift
# Make exclude list
shift
exclude=""
......@@ -43,11 +59,43 @@ echo "Excluding $exclude"
# Do backup
tar -czf /var/backups/localhost/$period/pvebackup_config_`hostname -s`_`date +%A`.tar.gz /root /etc 2> /dev/null
dovzdump=true
if [[ $period == 'weekly' || $period == 'monthly' ]]
then
maxfiles=1
if [[ $period == 'weekly' ]]
then
snapshotname="weekly_$((($(date +%-d)-1)/7+1))_pvebackup"
else
snapshotname="monthly_pvebackup"
fi
else
maxfiles=2
snapshotname="daily_`date +%u`_pvebackup"
if [[ $snapshot == true ]]
then
dovzdump=false
fi
fi
if [[ $snapshot == true ]]
then
vmlist=$(qm list | grep -v VMID | awk '{print $1}')
ctlist=$(pct list | grep -v VMID | awk '{print $1}')
for vm in $vmlist
do
echo "pvebakup: take $snapshotname snapshot on $vm virtual machine"
qm listsnapshot $vm | grep $snapshotname -q && (qm delsnapshot $vm $snapshotname && exit $?)
qm snapshot $vm $snapshotname -vmstate false || exit $?
done
for ct in $ctlist
do
echo "pvebakup: take $snapshotname snapshot on $ct container"
pct listsnapshot $ct | grep $snapshotname -q && (pct delsnapshot $ct $snapshotname && exit $?)
pct snapshot $ct $snapshotname || exit $?
done
fi
if [[ $dovzdump == true ]]
then
ionice -c3 /usr/bin/vzdump -compress 1 -mode snapshot -storage $period -stdexcludes 0 -maxfiles $maxfiles -all $exclude -exclude-path '/var/backups/localhost/.+'
exit $?
fi
ionice -c3 /usr/bin/vzdump -compress 1 -mode snapshot -storage $period -stdexcludes 0 -maxfiles $maxfiles -all $exclude -exclude-path '/var/backups/localhost/.+'
exit $?
#!/bin/bash
if [[ $1 == 'snapshot' ]]
then
snapshot="snapshot"
else
snapshot=""
fi
currentdir=$(dirname $0)
echo "Host node server backup script (c) Pedro Amador 2011-2014"
# Determine backup period
......@@ -18,11 +24,14 @@ fi
exclude=`head -n1 $currentdir/$period.exclude 2> /dev/null`
# Exec backup script
$currentdir/_backup_period.sh $period $exclude
$currentdir/_backup_period.sh $period $snapshot $exclude
resul_backup_period=$?
# Do other things
if [ $resul_backup_period == 0 ]
then
$currentdir/post_script.sh $period
$currentdir/post_script.sh $period $snapshot $exclude
exit $?
else
exit $resul_backup_period
fi
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment