diff options
author | onefang | 2020-09-08 21:31:56 +1000 |
---|---|---|
committer | onefang | 2020-09-08 21:31:56 +1000 |
commit | f92e3e7c49fef4d136ddd7d2e7f817cb0b255f4b (patch) | |
tree | d78dfa6bf1f8aa4ae47423ddcd3c778be8811e57 /scripts/gitAR.sh | |
parent | Add examples directory. (diff) | |
download | opensim-SC-f92e3e7c49fef4d136ddd7d2e7f817cb0b255f4b.zip opensim-SC-f92e3e7c49fef4d136ddd7d2e7f817cb0b255f4b.tar.gz opensim-SC-f92e3e7c49fef4d136ddd7d2e7f817cb0b255f4b.tar.bz2 opensim-SC-f92e3e7c49fef4d136ddd7d2e7f817cb0b255f4b.tar.xz |
Add the old bash scripts.
Most of these will eventually be rewritten as C + Lua.
Diffstat (limited to '')
-rwxr-xr-x | scripts/gitAR.sh | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/scripts/gitAR.sh b/scripts/gitAR.sh new file mode 100755 index 0000000..d988077 --- /dev/null +++ b/scripts/gitAR.sh | |||
@@ -0,0 +1,108 @@ | |||
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 | |||
14 | source common.sh | ||
15 | getPrgDir | ||
16 | |||
17 | type=$1 | ||
18 | title=$2 | ||
19 | date=$(date '+%F_%T') | ||
20 | |||
21 | # Convert the type to uppercase. | ||
22 | gar="_git$(echo -n ${type} | tr '[:lower:]' '[:upper:]')AR" | ||
23 | name=$(sanitize "${title}") | ||
24 | |||
25 | if [ -d ${PRGDIR}/../../backups/temp_backup${type}_${name} ]; then | ||
26 | echo "WARNING - Mess left over from last backup, not gonna run!" | ||
27 | mv ${PRGDIR}/../../backups/temp_backup${type}_${name}/*.oar ${PRGDIR}/../backups | ||
28 | exit 1 | ||
29 | fi | ||
30 | |||
31 | mkdir -p ${PRGDIR}/../../backups/temp_backup${type}_${name} | ||
32 | pushd ${PRGDIR}/../../backups/temp_backup${type}_${name} >/dev/null | ||
33 | if [ -f ../${name}${gar}.tar.xz ]; then | ||
34 | ionice -c3 nice -n 19 tar -xf ../${name}${gar}.tar.xz | ||
35 | else | ||
36 | mkdir -p ${name}${gar} | ||
37 | git init ${name}${gar} >log | ||
38 | fi | ||
39 | |||
40 | pushd ${name}${gar} >/dev/null | ||
41 | |||
42 | # Make sure stuff that's already compressed doesn't get compressed by git. | ||
43 | # Also tries to protect binaries from mangling. | ||
44 | cat >.gitattributes <<- zzzzEOFzzzz | ||
45 | *.bvh -delta -diff -text | ||
46 | *.jp2 -delta -diff -text | ||
47 | *.jpg -delta -diff -text | ||
48 | *.llmesh -delta -diff -text | ||
49 | *.ogg -delta -diff -text | ||
50 | *.png -delta -diff -text | ||
51 | *.r32 -delta -diff -text | ||
52 | *.tga -delta -diff -text | ||
53 | zzzzEOFzzzz | ||
54 | # Coz git insists. | ||
55 | git config user.email "opensim@$(hostname -A | cut -d ' ' -f 1)" | ||
56 | git config user.name "opensim" | ||
57 | |||
58 | # Git is such a pedantic bitch, let's just fucking ignore any errors it gives due to lack of anything to do. | ||
59 | # Even worse the OpenSim devs breaking logout tracking gives git plenty of nothing to do. lol | ||
60 | |||
61 | # Looping through them in case there's a bunch of I/OARs from previous versions of this script. | ||
62 | # Ignore files of zero size that OpenSim might create. | ||
63 | find ../.. -maxdepth 1 -type f -name "${name}-*.${type}ar" -size '+0c' | sort | while read file; do | ||
64 | # Deal with deletions in the inventory / sim, easy method, which becomes a nop for files that stay in the git add below. | ||
65 | git rm -fr * &>>../log #|| echo "ERROR - Could not clean git for ${file} !" >>../errors | ||
66 | if [ ! -f ../errors ]; then | ||
67 | ionice -c3 nice -n 19 tar -xzf "${file}" || echo "ERROR - Could not unpack ${file} !" >>../errors | ||
68 | fi | ||
69 | if [ ! -f ../errors ]; then | ||
70 | git add * &>>../log | ||
71 | git add */\* &>>../log #|| echo "ERROR - Could not add ${file} to git!" >>../errors | ||
72 | git add .gitattributes &>>../log | ||
73 | # Magic needed to figure out if there's anything to commit. | ||
74 | # After all the pain to get this to work, there's an ever changing timestamp in archive.xml that screws it up. | ||
75 | # Like this system didn't have enough timestamps in it already. lol | ||
76 | # TODO - I could sed out that timestamp, and put it back again based on the OAR file name when extracting. | ||
77 | # IARs don't seem to have the timestamp. | ||
78 | if t=$(git status --porcelain) && [ -z "${t}" ]; then | ||
79 | true | ||
80 | else | ||
81 | # Note this commit message has to be just the file name, as the ungitAR script uses it. | ||
82 | git commit -qm "$(basename ${file})" &>>../log || echo "ERROR - Could not commit ${file} !" >>../errors | ||
83 | fi | ||
84 | if [ ! -f ../errors ]; then | ||
85 | mv ${file} .. | ||
86 | fi | ||
87 | fi | ||
88 | if [ -f ../errors ]; then | ||
89 | exit 1 # Seems to only exit from this loop, not the script. Makes me want to rewrite this in a real language. lol | ||
90 | fi | ||
91 | done | ||
92 | |||
93 | #git gc --aggressive --prune=now # Takes a long time, doesn't gain much. Even worse, it increases the size of the resulting tarball. lol | ||
94 | |||
95 | popd >/dev/null | ||
96 | |||
97 | if [ ! -f errors ]; then | ||
98 | XZ_OPT="-9e" ionice -c3 nice -n 19 tar -c --xz ${name}${gar} -f ../${name}${gar}.tar.xz || echo "ERROR - Could not pack gitAR!" >>errors | ||
99 | fi | ||
100 | |||
101 | popd >/dev/null | ||
102 | |||
103 | if [ -f ${PRGDIR}/../../backups/temp_backup${type}_${name}/errors ]; then | ||
104 | echo "NOT cleaning up coz - " | ||
105 | cat ${PRGDIR}/../../backups/temp_backup${type}_${name}/errors | ||
106 | else | ||
107 | rm -fr ${PRGDIR}/../../backups/temp_backup${type}_${name} | ||
108 | fi | ||