summaryrefslogtreecommitdiff
path: root/tools/vkos.sh
blob: ebe0d667d2775fa8157031147063150abb592df4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
PROGNAME="$0"

die() {
	>&2 echo "error: $@"
	exit 1
}

usage() {
	cat <<EOF
usage: $PROGNAME [OPTIONS] COMMAND

Options:
	-b  use backup server
	-d  don't delete files after merge

Supported commands:
	list NODE
	fetch NODE PREFIX
	merge
EOF
	exit
}

[ -z "$1" ] && usage

COMMAND=
NODE=
PREFIX=
FROM_BACKUP=0
DONT_DELETE=0
while [[ $# -gt 0 ]]; do
	case "$1" in
		list)
			COMMAND="$1"
			NODE="$2"
			shift
			;;

		fetch)
			COMMAND="$1"
			NODE="$2"
			PREFIX="$3"
			shift; shift
			;;

		merge)
			COMMAND="$1"
			;;

		-b)
			FROM_BACKUP=1
			;;

		-d)
			DONT_DELETE=1
			;;

		*)
			die "unrecognized argument: $1"
			;;
	esac
	shift
done

[ -z "$COMMAND" ] && usage

if [ "$FROM_BACKUP" = "0" ]; then
	SRV_HOST=solarmon.ru
	SRV_PORT=60681
	SRV_USER=user
	SRV_DIR=/var/recordings
else
	SRV_HOST=srv_nas4
	SRV_PORT=22
	SRV_USER=root
	SRV_DIR=/var/storage1/solarmon/recordings
fi

case "$COMMAND" in
	list)
		[ -z "$NODE" ] && usage
		ssh -p${SRV_PORT} ${SRV_USER}@${SRV_HOST} "ls -rt --time creation \"${SRV_DIR}/${NODE}\""
		;;

	fetch)
		[ -z "$NODE" ] && usage
		[ -z "$PREFIX" ] && usage
		rsync -azPv -e "ssh -p${SRV_PORT}" ${SRV_USER}@${SRV_HOST}:"${SRV_DIR}/${NODE}/${PREFIX}*" .
		;;

	merge)
		args=
		if [ "$DONT_DELETE" = "0" ]; then args="-D"; fi
		$DIR/merge-recordings.py $args
		;;
esac