aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/scripts/gitAR.sh
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xscripts/gitAR.sh118
1 files changed, 118 insertions, 0 deletions
diff --git a/scripts/gitAR.sh b/scripts/gitAR.sh
new file mode 100755
index 0000000..2a067be
--- /dev/null
+++ b/scripts/gitAR.sh
@@ -0,0 +1,118 @@
1#!/bin/bash
2
3# Work around OpenSims slow database corruption bug by using git to store all old backups.
4# Try to squeeze every last byte out of the tarballs. Seems to cut the total storage size down to one third the size of just the raw I/OAR files.
5# Saves even more if there's been no changes.
6# On the other hand, these backup files will grow indefinately, the more changes, the faster it grows. I can live with that for more reliable backups that go back further.
7# Tries to avoid loosing data if things go wrong. I think the main remaining problem would be running out of space, in which case you have bigger problems to deal with.
8
9# Strategy - unpack the last one, unpack and commit any old I/OARs, pack up the result, delete it's working directory, THEN run the save i/oar.
10# Avoids having to sync with OpenSim finishing the current I/OAR, and as a bonus, an easy to deliver latest I/OAR for people that want it.
11
12# Not really meant to be called by users, so don't bother validating the input and such.
13
14type=$1
15title=$2
16
17# Figure out where we are, most of this mess is to troll through soft links.
18PRG="$0"
19while [ -h "${PRG}" ] ; do
20 ls=$(ls -ld "${PRG}")
21 link=`expr "${ls}" : '.*-> \(.*\)$'`
22 if expr "${link}" : '.*/.*' > /dev/null; then
23 PRG="${link}"
24 else
25 PRG=$(dirname "${PRG}")/"${link}"
26 fi
27done
28PRGDIR=$(dirname "${PRG}")
29pushd ${PRGDIR} >/dev/null
30PRGDIR=$(pwd)
31popd >/dev/null
32
33date=$(date '+%F_%T')
34
35# Sanitize the name. Not removing [ or ], couldn't get that to work, only important for Windows.
36name=$(echo "${title}" | sed -e 's/[\\/:\*\?"<>\|@#$%&\0\x01-\x1F\x27\x40\x60\x7F. ]/_/g' -e 's/^$/NONAME/')
37# Convert the type to uppercase.
38gar="_git$(echo -n ${type} | tr '[:lower:]' '[:upper:]')AR"
39
40if [ -d ${PRGDIR}/../../backups/temp_backup${type}_${name} ]; then
41 echo "WARNING - Mess left over from last backup, not gonna run!"
42 mv ${PRGDIR}/../../backups/temp_backup${type}_${name}/*.oar ${PRGDIR}/../backups
43 exit 1
44fi
45
46mkdir -p ${PRGDIR}/../../backups/temp_backup${type}_${name}
47pushd ${PRGDIR}/../../backups/temp_backup${type}_${name} >/dev/null
48if [ -f ../${name}${gar}.tar.xz ]; then
49 nice -n 19 tar -xf ../${name}${gar}.tar.xz
50else
51 mkdir -p ${name}${gar}
52 git init ${name}${gar} >log
53fi
54
55pushd ${name}${gar} >/dev/null
56
57# Make sure stuff that's already compressed doesn't get compressed by git.
58# Also tries to protect binaries from mangling.
59cat >.gitattributes <<- zzzzEOFzzzz
60*.bvh -delta -diff -text
61*.jp2 -delta -diff -text
62*.jpg -delta -diff -text
63*.llmesh -delta -diff -text
64*.ogg -delta -diff -text
65*.png -delta -diff -text
66*.r32 -delta -diff -text
67*.tga -delta -diff -text
68zzzzEOFzzzz
69git add .gitattributes &>>../log
70# Coz git insists.
71git config user.email "opensim@$(hostname -A | cut -d ' ' -f 1)"
72git config user.name "opensim"
73
74# Looping through them in case there's a bunch of I/OARs from previous versions of this script.
75find ../.. -maxdepth 1 -type f -name ${name}-*.${type}ar | sort | while read file; do
76 # Deal with deletions in the inventory / sim, easy method, which becomes a nop for files that stay in the git add below.
77 git rm -fr * &>>../log && \
78 nice -n 19 tar -xzf "${file}" || echo "ERROR - Could not unpack ${file} !" >>../errors
79 if [ ! -f ../errors ]; then
80 git add * &>>../log && git add */\* &>>../log
81 # Magic needed to figure out if there's anything to commit.
82 # After all the pain to get this to work, there's an ever changing timestamp in archive.xml that screws it up.
83 # Like this system didn't have enough timestamps in it already. lol
84 # TODO - I could sed out that timestamp, and put it back again based on the OAR file name when extracting.
85 # IARs don't seem to have the timestamp.
86 if t=$(git status --porcelain) && [ -z "${t}" ]; then
87 true
88 else
89 # Note this commit message has to be just the file name, as the ungitAR script uses it.
90 git commit -qm "$(basename ${file})" &>>../log || echo "ERROR - Could not commit ${file} !" >>../errors
91 fi
92 if [ ! -f ../errors ]; then
93 mv ${file} ..
94 fi
95 fi
96 if [ -f ../errors ]; then
97 exit 1 # Seems to only exit from this loop, not the script. Makes me want to rewrite this in a real language. lol
98 fi
99done
100
101#git gc --aggressive --prune=now # Takes a long time, doesn't gain much. Even worse, it increases the size of the resulting tarball. lol
102
103popd >/dev/null
104
105if [ ! -f errors ]; then
106 XZ_OPT="-9e" nice -n 19 tar -c --xz ${name}${gar} -f ../${name}${gar}.tar.xz || echo "ERROR - Could not pack gitAR!" >>errors
107fi
108
109popd >/dev/null
110
111if [ -f ${PRGDIR}/../../backups/temp_backup${type}_${name}/errors ]; then
112 echo "NOT cleaning up coz - "
113 cat ${PRGDIR}/../../backups/temp_backup${type}_${name}/errors
114else
115 rm -fr ${PRGDIR}/../../backups/temp_backup${type}_${name}
116fi
117
118echo -n ${name}