From 96eda14b7a1caff77da000a9a957b20ab1a1bb6e Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Tue, 8 Nov 2016 15:49:56 +1000 Subject: Lots of hacking up the scripts to work with the new setup, and more. --- scripts/backup-inventories.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 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..642d71d --- /dev/null +++ b/scripts/backup-inventories.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Figure out where we are, most of this mess is to troll through soft links. +PRG="$0" +while [ -h "${PRG}" ] ; do + ls=$(ls -ld "${PRG}") + link=`expr "${ls}" : '.*-> \(.*\)$'` + if expr "${link}" : '.*/.*' > /dev/null; then + PRG="${link}" + else + PRG=$(dirname "${PRG}")/"${link}" + fi +done +PRGDIR=$(dirname "${PRG}") +pushd ${PRGDIR} >/dev/null +PRGDIR=$(pwd) +popd >/dev/null + +# 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 + +# 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=GridUser.UserID and GridUser.Logout>${timestamp};" -ss | while read user; do + # Replace tab with space + user=${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. + # My big arsed 1 GB OAR takes about ten minutes to create, and maybe an hour to gitIOR! + sleep 200 +done -- cgit v1.1