From f92e3e7c49fef4d136ddd7d2e7f817cb0b255f4b Mon Sep 17 00:00:00 2001 From: onefang Date: Tue, 8 Sep 2020 21:31:56 +1000 Subject: Add the old bash scripts. Most of these will eventually be rewritten as C + Lua. --- scripts/backup-inventories.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 scripts/backup-inventories.sh (limited to 'scripts/backup-inventories.sh') 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 @@ +#!/bin/bash + +source common.sh +getPrgDir + +# Get the database credentials. +declare -A creds +while read -d ';' p; do + k=$(echo ${p} | cut -d '=' -f 1) + v=$(echo ${p} | cut -d '=' -f 2) + creds[${k}]="${v}" +done < <(grep ConnectionString ${PRGDIR}/../../config/config.ini | cut -d '"' -f 2) +# The above seems the best way to get bash to let the creds assignments survive outside the loop. + +# Only backup those that have not logged on since their last backup, but returning prims from sims will bypass this check. +timestamp=$(ls -o --time-style="+%s" ${PRGDIR}/../../backups/.keep | cut -d ' ' -f 5) +touch ${PRGDIR}/../../backups/.keep +# Well it was good in theory, but looks like they broke it in 8.2, no logging in or out updates to GridUser. + +# Get the user names, and back 'em up. +mysql --host="${creds[Data Source]}" "${creds[Database]}" --user="${creds[User ID]}" --password="${creds[Password]}" \ + -e "select FirstName,LastName from UserAccounts,GridUser where UserAccounts.PrincipalID=LEFT(GridUser.UserID,36) and GridUser.Login>${timestamp};" -ss | while read user; do + # Replace tab with space + user=${user// / } + # Find out the size of the last backup, base our later sleep on that, but do it now before backup-inventory packs it away. + sizeSleep=`sleepPerSize i "${user}"` + ${PRGDIR}/backup-inventory "${user}" + # Sleep for a while, so that there is plenty of time to do the backup, + # and we are not keeping the computer very busy if there are lots of users. + sleep ${sizeSleep} +done -- cgit v1.1