Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pigz as dep for Debian package. #53

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions control.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Package: @@PACKAGE@@
Section: utils
Version: @@VERSION@@
Depends: pigz
Priority: optional
Architecture: all
Homepage: http://www.enterpriseve.com/
Expand Down
195 changes: 117 additions & 78 deletions eve4pve-barc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Author: Daniele Corsini <[email protected]>
# Bastian Mäuser <[email protected]>

declare -r VERSION=0.2.5-renew
declare -r VERSION=0.2.6
declare -r NAME=$(basename "$0")
declare -r PROGNAME=${NAME%.*}

Expand Down Expand Up @@ -66,7 +66,8 @@ declare -g endts

declare -r renum='^[0-9]+$'
declare -r retime='([0-9]+)([d,w])$'
declare -r reimg='^.*\/([0-9]+)([a-zA-Z-]+)\.(.*)\.(diff|img).?(.*)?'
declare -r reimg='^.*\/([0-9]+)([0-9a-zA-Z-]+)\.(.*)\.(diff|img).?(.*)?'
declare -r repool='([a-zA-Z0-9-]+):(.*)'
declare -r redateex='^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$'


Expand Down Expand Up @@ -104,22 +105,23 @@ Usage:
$PROGNAME help
$PROGNAME version

$PROGNAME create --vmid=<string> --label=<string> --path=<string> [--keep=<integer>|--renew=<integer>]
--script=<string> --mail=<string> --unprotect-snap --syslog
$PROGNAME destroy --vmid=<string> --label=<string> --path=<string>
$PROGNAME enable --vmid=<string> --label=<string> --path=<string>
$PROGNAME disable --vmid=<string> --label=<string> --path=<string>

$PROGNAME backup --vmid=<string> --label=<string> --path=<string> [--keep=<integer>|--renew=<integer>]
--script=<string> --mail=<string> --unprotect-snap --syslog
$PROGNAME restore --vmid=<string> --label=<string> --path=<string>
--script=<string> --syslog

$PROGNAME status --vmid=<string> --label=<string> --path=<string>
$PROGNAME clean --vmid=<string> --label=<string> --path=<string> [--keep=<integer>|--renew=<integer>]
$PROGNAME reset --vmid=<string> --label=<string>
$PROGNAME assemble --vmid=<string> --label=<string> --path=<string>
--script=<string>
$PROGNAME create --vmid=<string> --label=<string> --path=<string> [--keep=<integer>|--renew=<integer>]
--script=<string> --mail=<string> --unprotect-snap --syslog
$PROGNAME destroy --vmid=<string> --label=<string> --path=<string>
$PROGNAME enable --vmid=<string> --label=<string> --path=<string>
$PROGNAME disable --vmid=<string> --label=<string> --path=<string>

$PROGNAME backup --vmid=<string> --label=<string> --path=<string> [--keep=<integer>|--renew=<integer>]
--script=<string> --mail=<string> --unprotect-snap --syslog
$PROGNAME restore --vmid=<string> --label=<string> --path=<string>
--script=<string> --syslog

$PROGNAME status --vmid=<string> --label=<string> --path=<string>
$PROGNAME clean --vmid=<string> --label=<string> --path=<string> [--keep=<integer>|--renew=<integer>]
$PROGNAME housekeep --vmid=<string> [--keep=<integer>|--renew=<integer>]
$PROGNAME reset --vmid=<string> --label=<string>
$PROGNAME assemble --vmid=<string> --label=<string> --path=<string>
--script=<string>
Commands:
version Show version program
help Show help program
Expand Down Expand Up @@ -239,8 +241,7 @@ function parse_opts(){
local args
args=$(getopt \
--options '' \
--longoptions=path:,vmid:,label:,keep:,renew:,retain:,cksum:,ckmethod:,iothreads:,compress:,compressthreads:,mail: \
--longoptions=script:,syslog,debug,dry-run,unprotect-snap,qemu-freeze \
--longoptions=path:,vmid:,label:,keep:,renew:,retain:,cksum:,ckmethod:,iothreads:,compress:,compressthreads:,mail:,script:,syslog,debug,dry-run,unprotect-snap,qemu-freeze \
--name "$PROGNAME" \
-- "$@") \
|| end_process 128
Expand Down Expand Up @@ -567,7 +568,7 @@ function get_disks_from_config(){
[[ "$line" == "" ]] && break
echo "$line"
done < "$file_config" | \
grep -P '^(?:((?:virtio|ide|scsi|sata|mp)\d+)|rootfs): ' | \
grep -P '^(?:((?:efidisk|virtio|ide|scsi|sata|mp)\d+)|rootfs): ' | \
grep -v -P 'cdrom|none' | \
grep -v -P 'backup=0' | \
awk '{ split($0,a,","); split(a[1],b," "); print b[2]}')
Expand Down Expand Up @@ -725,14 +726,6 @@ function backup(){
fi
export_type[$export_idx]="image"
else
if [ "$renew" == true ]; then
log info "VM $vm_id - Renew policy requires full run for $disk"
backup_file="$backup_file$EXT_IMAGE"
else
log info "VM $vm_id - Renew policy tolerates incremental run for $disk"
backup_file="$backup_file$EXT_DIFF"
fi

#Snapshot Housekeeping..
#find last snapshot in ceph
latest_snap=$(rbd snap ls "$image_spec" | \
Expand All @@ -741,10 +734,11 @@ function backup(){

#not exist snapshot on rbd
if [ -z "$latest_snap" ]; then
log error "VM $vm_id - Ceph last snapshot '$image_spec' not found!";
call_hook_script "export-diff-abort" "-" "-"
rc=30
break;
log warn "VM $vm_id - Ceph last snapshot '$image_spec' not found! Running Full";
renew=true
#call_hook_script "export-diff-abort" "-" "-"
#rc=30
#break;
fi

#verify exist last snapshot ceph in file backup
Expand Down Expand Up @@ -777,12 +771,17 @@ function backup(){
break;
fi

export_latest_snap[$export_idx]="$latest_snap"
if [ "$renew" == true ]; then
log info "VM $vm_id - Renew policy requires full run for $disk"
backup_file="$backup_file$EXT_IMAGE"
export_type[$export_idx]="image"
else
log info "VM $vm_id - Renew policy tolerates incremental run for $disk"
backup_file="$backup_file$EXT_DIFF"
export_type[$export_idx]="diff"
fi

export_latest_snap[$export_idx]="$latest_snap"
fi
snapshotok=$((snapshotok+1))

Expand Down Expand Up @@ -919,6 +918,47 @@ function backup(){
end_process $rc
}

function housekeep() {

local -i rc=0;
local vmname

parse_opts "$@"

startts=$(date +%s)
log info "ACTION: Housekeep"

local timestamp; timestamp=$(date +%Y%m%d%H%M%S)
log info "Start manual Housekeeping $(date "+%F %T")"

#create pid file
# local pid_file="/var/run/$PROGNAME.pid"
# if [[ -e "$pid_file" ]]; then
# local pid; pid=$(cat "${pid_file}")
# if ps -p "$pid" > /dev/null 2>&1; then
# log error "Process already running with pid ${pid}"
# end_process 1
# fi
# fi

# if ! echo $$ > "$pid_file"; then
# log error "Could not create PID file $pid_file"
# end_process 1
# fi


map_vmids_to_host


for vm_id in $vm_ids; do
log info "VM $vm_id - -------- manual Housekeeping -------"#
get_path
housekeeping
done

exit 0
}

function get_size_file(){
echo $(ls -l "$1" | awk '{print $5}')
}
Expand All @@ -928,60 +968,58 @@ function sum_size_file(){
}

function housekeeping() {
log info "Start houskeeping()"
local image=''
local keepfile=true
local imgreached=false
local factor=86400 #tbd
local filecount=0

local file_config; file_config=$(get_config_file)
[ -z "$file_config" ] && continue

if [[ $opt_retain =~ $retime ]]; then
maxage=$((${BASH_REMATCH[1]}*$factor))
for image in $(ls -r $path_backup/*{$EXT_DIFF,$EXT_IMAGE}{.zz,.gz,.bz2,} 2>/dev/null); do
if [[ "$image" =~ $reimg ]]; then
ext=${BASH_REMATCH[4]}
ts=${BASH_REMATCH[1]}
if [[ $ts =~ $redateex ]]; then
fdate=$((`date --date "${BASH_REMATCH[1]}/${BASH_REMATCH[2]}/${BASH_REMATCH[3]} ${BASH_REMATCH[4]}:${BASH_REMATCH[5]}:${BASH_REMATCH[6]}" +%s`))
else
rc=10
log error "Houskeeping Error"
break;
fi
age=$((`date +"%s"`-$fdate))
if [[ $age -ge $maxage ]]; then
if [[ ".$ext" == "$EXT_IMAGE" ]]; then
imgreached=true
for disks in $(get_disks_from_config "$file_config"); do
log info "Housekeeping for Disk $disks - maxage: $maxage"
[[ "$disks" =~ $repool ]]
pool=${BASH_REMATCH[1]}
disk=${BASH_REMATCH[2]}
keepfile=true
imgreached=false
image_spec=$(get_image_spec "$disks")
suffix_backup_file=${image_spec//\//.}
list=$(find $path_backup -regextype posix-egrep -regex "$path_backup/[0-9]+$suffix_backup_file.(diff|img).(gz|bz2|zz)"|sort -nr)
for image in $list; do
if [[ "$image" =~ $reimg ]]; then
ext=${BASH_REMATCH[4]}
ts=${BASH_REMATCH[1]}
if [[ $ts =~ $redateex ]]; then
#extract file time
fdate=$((`date --date "${BASH_REMATCH[1]}/${BASH_REMATCH[2]}/${BASH_REMATCH[3]} ${BASH_REMATCH[4]}:${BASH_REMATCH[5]}:${BASH_REMATCH[6]}" +%s`))
else
rc=10
log error "Houskeeping Error"
break;
fi
fi
if ! [[ "$keepfile" == true ]]; then
log info "VM $vm_id - Houskeeping deleting: $image"
do_run "rm $image*"
do_run "rm $path_backup/$ts.conf"
fi
if [[ "$imgreached" == true ]]; then
keepfile=false
fi
fi
done
elif [[ $opt_retain =~ $renum ]]; then
for image in $(ls -r $path_backup/*{$EXT_DIFF,$EXT_IMAGE}{.zz,.gz,.bz2,} 2>/dev/null); do
if [[ "$image" =~ $reimg ]]; then
filecount=$((filecount+1))
ext=${BASH_REMATCH[4]}
ts=${BASH_REMATCH[1]}
if [[ "$filecount" -ge "$opt_retain" ]]; then
if [[ ".$ext" == "$EXT_IMAGE" ]]; then
imgreached=true
age=$((`date +"%s"`-$fdate))
if [[ $age -ge $maxage ]]; then
if [[ ".$ext" == "$EXT_IMAGE" ]]; then
imgreached=true
fi
fi
if ! [[ "$keepfile" == true ]]; then
log info "VM $vm_id - Houskeeping deleting: $image"
do_run "rm $image*"
do_run "rm $path_backup/$ts.conf"
else
log debug "VM $vm_id - Houskeeping keeping: $image"
fi
if [[ "$imgreached" == true ]]; then
keepfile=false
fi
fi
if ! [[ "$keepfile" == true ]]; then
log info "VM $vm_id - Houskeeping deleting: $image"
do_run "rm $image*"
do_run "rm $path_backup/$ts.conf"
fi
if [[ "$imgreached" == true ]]; then
keepfile=false
fi
fi
done
done
fi
}
Expand Down Expand Up @@ -1426,6 +1464,7 @@ function main(){
backup) backup "$@";;
restore) restore "$@";;
clean) clean "$@";;
housekeeping) housekeep "$@";;
status) status "$@";;
reset) reset "$@";;
assemble) assemble "$@";;
Expand Down