aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/scripts/backup-inventories.sh
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xscripts/backup-inventories.sh31
1 files changed, 31 insertions, 0 deletions
diff --git a/scripts/backup-inventories.sh b/scripts/backup-inventories.sh
new file mode 100755
index 0000000..e4e7158
--- /dev/null
+++ b/scripts/backup-inventories.sh
@@ -0,0 +1,31 @@
1#!/bin/bash
2
3source common.sh
4getPrgDir
5
6# Get the database credentials.
7declare -A creds
8while read -d ';' p; do
9 k=$(echo ${p} | cut -d '=' -f 1)
10 v=$(echo ${p} | cut -d '=' -f 2)
11 creds[${k}]="${v}"
12done < <(grep ConnectionString ${PRGDIR}/../../config/config.ini | cut -d '"' -f 2)
13# The above seems the best way to get bash to let the creds assignments survive outside the loop.
14
15# Only backup those that have not logged on since their last backup, but returning prims from sims will bypass this check.
16timestamp=$(ls -o --time-style="+%s" ${PRGDIR}/../../backups/.keep | cut -d ' ' -f 5)
17touch ${PRGDIR}/../../backups/.keep
18# Well it was good in theory, but looks like they broke it in 8.2, no logging in or out updates to GridUser.
19
20# Get the user names, and back 'em up.
21mysql --host="${creds[Data Source]}" "${creds[Database]}" --user="${creds[User ID]}" --password="${creds[Password]}" \
22 -e "select FirstName,LastName from UserAccounts,GridUser where UserAccounts.PrincipalID=LEFT(GridUser.UserID,36) and GridUser.Login>${timestamp};" -ss | while read user; do
23 # Replace tab with space
24 user=${user// / }
25 # Find out the size of the last backup, base our later sleep on that, but do it now before backup-inventory packs it away.
26 sizeSleep=`sleepPerSize i "${user}"`
27 ${PRGDIR}/backup-inventory "${user}"
28 # Sleep for a while, so that there is plenty of time to do the backup,
29 # and we are not keeping the computer very busy if there are lots of users.
30 sleep ${sizeSleep}
31done