-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuckets-restore-from-backups
executable file
·127 lines (100 loc) · 2.17 KB
/
buckets-restore-from-backups
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
#
# This script restores all existing buckets from a backup
#
# Errors are fatal
set -e
GO=""
SRC=""
if test ! "$1"
then
echo "! "
echo "! Syntax: $0 /path/to/backup/directory [ --go ]"
echo "! "
exit 1
fi
SRC=$1
if test "$2" == "--go"
then
GO=1
fi
if test ! -d "$SRC"
then
echo "! "
echo "! Backup directory '$SRC' does not exist or is not readable!"
echo "! "
exit 1
fi
SPLUNK_HOME="/var/splunk"
BUCKET_DIR="${SPLUNK_HOME}/var/lib/splunk/septa_analytics/db/cold"
if test "$GO"
then
$SPLUNK_HOME/bin/splunk stop
else
echo "# "
echo "# If I was run with --go on the command line, "
echo "# I would be stopping splunk now... "
echo "# "
fi
echo "# "
echo "# About to restore buckets from '${SRC}' to '${BUCKET_DIR}'..."
echo "# "
echo "# "
echo "# Doing temporary operations in ${TMP_DIR}..."
echo "# "
#
# Find our buckets and move them
#
NEW_ID=10000
for FILE in $(ls -1 $SRC/*.tgz |sort )
do
TMP_DIR=$(mktemp -d)
pushd $TMP_DIR > /dev/null
echo "# "
echo "# Restoring '${FILE}' to '${BUCKET_DIR}'..."
echo "# temp dir: ${TMP_DIR}"
#
# Extract our file, get the ID number, and change it to a new ID number
#
tar xfz $FILE
EXTRACTED_DIR=$(ls -1)
echo "# Extracted into directory: $EXTRACTED_DIR"
EXTRACTED_ID=$(echo $EXTRACTED_DIR |cut -d_ -f4 | cut -d. -f1)
echo "# Extracted ID: $EXTRACTED_ID"
echo "# New ID: $NEW_ID"
NEW_DIR=$(echo $EXTRACTED_DIR | sed -e s/_${EXTRACTED_ID}$/_${NEW_ID}/)
echo "# New File: $NEW_DIR"
mv $EXTRACTED_DIR $NEW_DIR
NEW_BUCKET_DIR="${BUCKET_DIR}/${NEW_DIR}"
echo "# New final location: $NEW_BUCKET_DIR"
echo "# Moving '${NEW_DIR}' to '${BUCKET_DIR}'..."
if test "$GO"
then
if test ! -d ${NEW_BUCKET_DIR}
then
mv ${NEW_DIR} ${BUCKET_DIR}
else
echo "# "
echo "# Oops! Target '${NEW_BUCKET_DIR}' already exists, skpping this one!"
echo "# "
fi
else
echo "#"
echo "# (...if I was run with --go on the command line...)"
fi
echo "#"
echo "#"
#
# Increment our New ID, get out of our old directory, and remove it
#
NEW_ID=$((NEW_ID + 1))
popd >/dev/null
rm -rf ${TMP_DIR}
done
if test "$GO"
then
echo "# "
echo "# Success! "
echo "# Be sure to start up Splunk now. :-)"
echo "# "
fi