-
Notifications
You must be signed in to change notification settings - Fork 5
/
concat_partial_export.sh
executable file
·70 lines (61 loc) · 2.02 KB
/
concat_partial_export.sh
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
#!/bin/bash
# path to all the source directories (contents of the extracted hipchat tarballs)
# newest directory should be at the end
SOURCEDIR="/persistent/hipchat/2016 /persistent/hipchat/2017 /persistent/hipchat/2018 /persistent/hipchat/2019 /persistent/hipchat/2019-09"
# path to the destination directory that will hold all the merged data
TARGETDIR="/persistent/hipchat/overall"
LOG="$TARGETDIR/merge.log"
# create target directory if it does not exist
if ! test -d "$TARGETDIR"; then
echo -n "Creating target directory $TARGETDIR..."
if ! mkdir -p "$TARGETDIR"; then
echo "failed."
exit 1
fi
echo "done."
fi
# empty the logfile
echo "Merge started at $(date)" > $LOG
# merge room and user structure as well as attachments (but not the posts itself)
for sdir in $SOURCEDIR; do
if ! test -d $sdir; then
echo "sdir does not exist, exiting"
exit 1
fi
echo -n "Syncing structure and attachments from $sdir to $TARGETDIR..."
rsync --exclude /history.json -av $sdir/ $TARGETDIR/ >> $LOG 2>&1
echo "done."
done
# copy user and room metadata from the most recent part (only the most recent information is relevant)
echo -n "Copying $sdir/users.json to $TARGETDIR..."
if ! cp -f $sdir/users.json $TARGETDIR; then
echo "failed."
exit 1
fi
echo "done."
echo -n "Copying $sdir/rooms.json to $TARGETDIR..."
if ! cp -f $sdir/rooms.json $TARGETDIR; then
echo "failed."
exit 1
fi
echo "done."
# merge rooms and user history
for type in rooms users; do
for dir in $TARGETDIR/$type/*; do
ID=$(basename $dir)
SOURCEFILES=""
for sdir in $SOURCEDIR; do
needle=$sdir/$type/$ID/history.json
test -f $needle && SOURCEFILES="$SOURCEFILES $needle"
done
if [ "$SOURCEFILES" != "" ]; then
echo -n "Merge history ($type/$ID)..."
if ! jq -s add $SOURCEFILES > $TARGETDIR/$type/$ID/history.json; then
echo "failed."
else
echo "done."
fi
fi
done
done
echo "Merge finished at $(date)" >> $LOG