diff options
Diffstat (limited to 'scripts/backup-inventories.sh')
-rwxr-xr-x | scripts/backup-inventories.sh | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/scripts/backup-inventories.sh b/scripts/backup-inventories.sh new file mode 100755 index 0000000..642d71d --- /dev/null +++ b/scripts/backup-inventories.sh | |||
@@ -0,0 +1,42 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | # Figure out where we are, most of this mess is to troll through soft links. | ||
4 | PRG="$0" | ||
5 | while [ -h "${PRG}" ] ; do | ||
6 | ls=$(ls -ld "${PRG}") | ||
7 | link=`expr "${ls}" : '.*-> \(.*\)$'` | ||
8 | if expr "${link}" : '.*/.*' > /dev/null; then | ||
9 | PRG="${link}" | ||
10 | else | ||
11 | PRG=$(dirname "${PRG}")/"${link}" | ||
12 | fi | ||
13 | done | ||
14 | PRGDIR=$(dirname "${PRG}") | ||
15 | pushd ${PRGDIR} >/dev/null | ||
16 | PRGDIR=$(pwd) | ||
17 | popd >/dev/null | ||
18 | |||
19 | # Get the database credentials. | ||
20 | declare -A creds | ||
21 | while read -d ';' p; do | ||
22 | k=$(echo ${p} | cut -d '=' -f 1) | ||
23 | v=$(echo ${p} | cut -d '=' -f 2) | ||
24 | creds[${k}]="${v}" | ||
25 | done < <(grep ConnectionString ${PRGDIR}/../config/config.ini | cut -d '"' -f 2) | ||
26 | # The above seems the best way to get bash to let the creds assignments survive outside the loop. | ||
27 | |||
28 | # Only backup those that have not logged on since their last backup, but returning prims from sims will bypass this check. | ||
29 | timestamp=$(ls -o --time-style="+%s" ${PRGDIR}/../backups/.keep | cut -d ' ' -f 5) | ||
30 | touch ${PRGDIR}/../backups/.keep | ||
31 | |||
32 | # Get the user names, and back 'em up. | ||
33 | mysql --host="${creds[Data Source]}" "${creds[Database]}" --user="${creds[User ID]}" --password="${creds[Password]}" \ | ||
34 | -e "select FirstName,LastName from UserAccounts,GridUser where UserAccounts.PrincipalID=GridUser.UserID and GridUser.Logout>${timestamp};" -ss | while read user; do | ||
35 | # Replace tab with space | ||
36 | user=${user// / } | ||
37 | ${PRGDIR}/backup-inventory "${user}" | ||
38 | # Sleep for a while, so that there is plenty of time to do the backup, | ||
39 | # and we are not keeping the computer very busy if there are lots of users. | ||
40 | # My big arsed 1 GB OAR takes about ten minutes to create, and maybe an hour to gitIOR! | ||
41 | sleep 200 | ||
42 | done | ||