#!/bin/bash
. /usr/syno/bin/jsoncmd

main()
{
	local export_path=$(jget "${SYNOPKG_BKP_INPUT}" ".temp_path")

	if [ $? -ne 0 ];then
		jerr "bad parameters"
		exit 1
	fi

	"${SYNOPKG_PKGPATH}/target/bin/syno_config_backup_restore" backup "${export_path}"
	if [ 0 -ne $? ]; then
		jerrstr "error" "config_backup_fail_msg"
		exit 1
	fi

	tar zcf /var/services/tmp/backup.tar.gz -C "${export_path}" ./ && mv /var/services/tmp/backup.tar.gz "${export_path}"
	if [ 0 -ne $? ]; then
		jerrstr "error" "config_backup_fail_msg"
		exit 1
	fi

	jout_begin
	joutstr "app_data_version" "1.1"
	jout_end

	exit 0
}

main
