Skip to content

Commit

Permalink
Add support krdb
Browse files Browse the repository at this point in the history
Add all-??? for specific host
  • Loading branch information
franklupo committed Feb 13, 2017
1 parent 8994c23 commit c87f191
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 46 deletions.
15 changes: 7 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
VERSION=$(shell ./eve4pve-barc version)
DATE=$(shell LANG=en_us_8859_1; date '+%b %d, %Y')

PACKAGE=eve4pve-barc

VERSION=$(shell ./${PACKAGE} version)
DATE=$(shell LANG=en_us_8859_1; date '+%b %d, %Y')
DESTDIR=
PREFIX=/usr
SBINDIR=${PREFIX}/sbin
Expand Down Expand Up @@ -30,7 +28,7 @@ install:

install -d ${DESTDIR}${MAN8DIR}
install -m 0644 ${PACKAGE}.8 ${DESTDIR}${MAN8DIR}
gzip ${DESTDIR}${MAN8DIR}/${PACKAGE}.8
gzip -n -9 ${DESTDIR}${MAN8DIR}/${PACKAGE}.8

install -d ${DESTDIR}${EXAMPLE}
install -m 0755 script-hook.sh ${DESTDIR}${EXAMPLE}
Expand All @@ -41,7 +39,7 @@ deb ${DEB}:
rm -rf debian
mkdir debian

$(shell ./eve4pve-barc help --no-logo > help.tmp)
$(shell ./${PACKAGE} help --no-logo > help.tmp)
sed '/@@COPYRIGHT@@/r copyright' ${PACKAGE}.8.template | \
sed "/@@COPYRIGHT@@/d" | \
sed '/@@SYNOPSIS@@/r help.tmp' | \
Expand All @@ -55,13 +53,14 @@ deb ${DEB}:
install -d -m 0755 debian/DEBIAN
sed -e s/@@VERSION@@/${VERSION}/ -e s/@@PACKAGE@@/${PACKAGE}/ <control.in >debian/DEBIAN/control
install -D -m 0644 copyright debian/${DOCDIR}/copyright
install -m 0644 changelog.Debian debian/${DOCDIR}/
gzip -9 debian/${DOCDIR}/changelog.Debian
install -m 0644 changelog debian/${DOCDIR}/
gzip -n -9 debian/${DOCDIR}/changelog
dpkg-deb --build debian
mv debian.deb ${DEB}
rm -rf debian
rm ${PACKAGE}.8
rm help.tmp
#lintian ${DEB}

.PHONY: clean
clean:
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ Commands:
Options:
--vmid=string The ID of the VM, comma separated (es. 100,101,102),
'all' for all known guest systems.
'all-???' for all known guest systems in specific host (es. all-pve1, all-\$(hostname)),
'all' for all known guest systems in cluster.
--label=string Is usually 'hourly', 'daily', 'weekly', or 'monthly'.
--path=string Path destination backup.
--keep=integer Specify the number of backup which should will keep, Default 1.
Expand All @@ -76,8 +77,10 @@ In backup export image and config file VM/CT.
* Hook script
* Multiple VM single execution
* Copy config and firewall files
* Export any vm in cluster
* Export any vm in cluster 'all'
* Export any vm in specific host 'all-hostname'
* Show size of backup and incremental
* Check 'No backup' flag in disk configuration

# Configuration and use
Download package eve4pve-barc_?.?.?-?_all.deb, on your Proxmox VE host and install:
Expand Down
7 changes: 7 additions & 0 deletions changelog.Debian → changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
eve4pve-barc (0.1.3)

* Support krbd flag
* Add all-^??? hostname

-- EnterpriseVE Support Team <support@enterpriseve.com> 13 Feb 2017

eve4pve-barc (0.1.2)

* Export any vm in cluster
Expand Down
2 changes: 1 addition & 1 deletion control.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: @@PACKAGE@@
Section: Proxmox
Section: utils
Version: @@VERSION@@
Priority: optional
Architecture: all
Expand Down
97 changes: 62 additions & 35 deletions eve4pve-barc
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
# EnterpriseVE Backup And Restore Ceph for Proxmox VE.
# Author: Daniele Corsini <daniele.corsini@enterpriseve.com>

declare -r VERSION=0.1.2
declare -r VERSION=0.1.3
declare -r NAME=$(basename "$0")
declare -r PROGNAME=${NAME%.*}

declare -r PVE_DIR="/etc/pve"
declare -r PVE_FIREWALL="$PVE_DIR/firewall"
declare -r QEMU_CONF="$PVE_DIR/nodes/*/qemu-server"
declare -r LXC_CONF="$PVE_DIR/nodes/*/lxc"
declare -r PVE_NODES="$PVE_DIR/nodes"
declare -r QEMU='qemu-server'
declare -r LXC='lxc'
declare -r QEMU_CONF_CLUSTER="$PVE_NODES/*/$QEMU"
declare -r LXC_CONF_CLUSTER="$PVE_NODES/*/$LXC"

declare -r EXT_IMAGE='.img'
declare -r EXT_DIFF='.diff'
Expand Down Expand Up @@ -82,7 +85,8 @@ Commands:
Options:
--vmid=string The ID of the VM, comma separated (es. 100,101,102),
'all' for all known guest systems.
'all-???' for all known guest systems in specific host (es. all-pve1, all-\$(hostname)),
'all' for all known guest systems in cluster.
--label=string Is usually 'hourly', 'daily', 'weekly', or 'monthly'.
--path=string Path destination backup.
--keep=integer Specify the number of backup which should will keep, Default 1.
Expand Down Expand Up @@ -121,6 +125,32 @@ function log(){
esac
}

function get_vm_ids(){
local data=''
local conf=''

while [ $# -gt 0 ]; do
for conf in $1; do
[ ! -e "$conf" ] && break

conf=$(basename "$conf")
[ "$data" != '' ] && data="$data,"
data="$data${conf%.*}"
done
shift
done

echo "$data"
}

function exist_file(){
local file=''
for file in $1; do
[ -e "$file" ] && return 0 || return 1
break
done
}

function parse_opts(){
local action=$1
shift
Expand Down Expand Up @@ -154,28 +184,28 @@ function parse_opts(){
[ ! -d "$opt_path_backup" ] && { log info "Path Backup is not set"; exit 1; }
[ -z "$opt_vm_ids" ] && { log info "VM id is not set."; exit 1; }
if [ "$opt_vm_ids" = "all" ]; then
vm_ids=''
local conf=''
#all in cluster

#VM
for conf in $QEMU_CONF/*$EXT_CONF; do
[ ! -e "$conf" ] && break
local data=''
data=$(get_vm_ids "$QEMU_CONF_CLUSTER/*$EXT_CONF" "$LXC_CONF_CLUSTER/*$EXT_CONF")
vm_ids=$(echo "$data" | tr ',' '\n')

conf=$(basename "$conf")
[ "$vm_ids" != '' ] && vm_ids="$vm_ids,"
vm_ids="$vm_ids${conf%.*}"
done
elif [[ "$opt_vm_ids" == "all-"* ]]; then
#all in specific host

#CT
for conf in $LXC_CONF/*$EXT_CONF; do
[ ! -e "$conf" ] && break
local host=${opt_vm_ids#*-}

if ! exist_file "$PVE_NODES/$host"; then
log info "Host not found!"
exit 1
fi

conf=$(basename "$conf")
[ "$vm_ids" != '' ] && vm_ids="$vm_ids,"
vm_ids="$vm_ids${conf%.*}"
done
local data=''
data=$(get_vm_ids "$PVE_NODES/$host/$QEMU/*$EXT_CONF" "$PVE_NODES/$host/$LXC/*$EXT_CONF")
[ -z "$data" ] && { log info "VM id is not set."; exit 1; }

vm_ids=$(echo "$data" | tr ',' '\n')

vm_ids=$(echo "$vm_ids" | tr ',' '\n')
else
#comma separated
vm_ids=$(echo "$opt_vm_ids" | tr ',' '\n')
Expand Down Expand Up @@ -355,14 +385,6 @@ function call_hook_script(){
fi
}

function exist_file(){
local file=''
for file in $1; do
[ -e "$file" ] && return 0 || return 1
break
done
}

function backup(){
parse_opts "$@"

Expand All @@ -389,15 +411,15 @@ function backup(){
local file_config=''

#check tecnology
if exist_file "$QEMU_CONF/$vm_id$EXT_CONF"; then
file_config=$(ls $QEMU_CONF/$vm_id$EXT_CONF)
if exist_file "$QEMU_CONF_CLUSTER/$vm_id$EXT_CONF"; then
file_config=$(ls $QEMU_CONF_CLUSTER/$vm_id$EXT_CONF)

if ! grep -q 'agent: 1' < "$file_config"; then
log info "VM $vm_id consider enabling QEMU agent see https://pve.proxmox.com/wiki/Qemu-guest-agent"
fi

elif exist_file "$LXC_CONF/$vm_id$EXT_CONF"; then
file_config=$(ls $LXC_CONF/$vm_id$EXT_CONF)
elif exist_file "$LXC_CONF_CLUSTER/$vm_id$EXT_CONF"; then
file_config=$(ls $LXC_CONF_CLUSTER/$vm_id$EXT_CONF)

else
log error "VM $vm_id - Unknown tecnology"
Expand All @@ -423,8 +445,13 @@ function backup(){
for disk in $disks; do
#check rbd device image-spec is pool-name/image-name
local image_spec;
image_spec=$(pvesm path "$disk" | grep 'ceph' | awk '{ split($0,a,":"); print a[2]}')
[ -z "$image_spec" ] && continue

#if krbd enable
image_spec=$(pvesm path "$disk" | grep '^/dev/rbd/' | sed -e "s/^\/dev\/rbd\///")
if [ -z "$image_spec" ]; then
image_spec=$(pvesm path "$disk" | grep '/ceph/' | awk '{ split($0,a,":"); print a[2]}')
[ -z "$image_spec" ] && continue
fi

#pool-name/image-name@snap-name
local current_snap="$image_spec@$snap_name_prefix$timestamp"
Expand Down

0 comments on commit c87f191

Please sign in to comment.