#!/bin/bash
{# LIST="
/etc/etcd
/etc/ssl/etcd
{{data_dir}}
"
#}
{# KLOUDS_ETC_PATH=${KLOUDS_ETC_PATH:-{{klouds_etc_path | default(value="/etc/klouds")}}}
KLOUDS_LIB_PATH=${KLOUDS_LIB_PATH:-{{klouds_lib_path | default(value="/var/lib/klouds")}}}
KLOUDS_SAVE_PATH=${KLOUDS_SAVE_PATH:-{{klouds_save_path | default(value="/var/lib/klouds/save")}}}

[ -r "$KLOUDS_ETC_PATH/backup_env" ] && . "$KLOUDS_ETC_PATH/backup_env"
#}

_etcd_cmd() {
	sudo etcdctl \
	--endpoints {{taskserv.etcd_protocol}}://{{taskserv.peer_ip}}:{{taskserv.peer_port}} \
	{% if taskserv.ssl_mode != "" -%}
	--cacert /etc/ssl/etcd/ca.crt  \
	--cert /etc/ssl/etcd/{{taskserv.cluster_name}}.crt  \
	--key /etc/ssl/etcd/{{taskserv.cluster_name}}.key  \
	{%- endif %}
	$*
}

_make_snapshot() {
	[ -z "$1" ] && echo "No path to create etcd snapshot" && exit 1
	_etcd_cmd snapshot save "$1"
}

_verify_snapshot() {
	[ -z "$1" ] && echo "No path to verify etcd snapshot" && exit 1
	[ -r "$1" ] && echo "No path fount to verify etcd snapshot" && exit 1
	_etcd_cmd --write-out=table snapshot status "$1"
}

_service_backup_verify() {
	_verify_snapshot $1
	return 0
}
_service_backup() {
	_make_snapshot $1
	return 0
}
_service_restore() {
	return 0
}
{# local has_run="$(type -t _run_init)"
[ -n "$has_run" ] && _run_init
#}