Redbrick User management tool
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
958 B

  1. #!/bin/sh
  2. #
  3. # Dump databases to committee folder.
  4. #
  5. # $Id: update_userdb_dumps.sh,v 1.4 2002/02/16 21:50:54 cns Exp cns $
  6. #
  7. OUT=/local/committee/userdb
  8. PSQL="/usr/local/pgsql/bin/psql -h localhost -d userdb"
  9. PG_DUMP="/usr/local/pgsql/bin/pg_dump -h localhost -d userdb"
  10. USERDB_BACKUP="/local/admin/scripts/users/backup-of-userdb.dump"
  11. printf "$OUT dumps: "
  12. # Dump each database and keep a copy of yesterday's database
  13. # (for doing comparisons/diffs).
  14. #
  15. for i in users students reserved; do
  16. $PSQL -c "select * from $i" > $OUT/$i.new
  17. # Only rotate them if there was no error from psql
  18. # and a non-empty dump was generated.
  19. #
  20. if [ $? -eq 0 -a -s $OUT/$i.new ]; then
  21. printf "$i "
  22. mv $OUT/$i $OUT/$i.yesterday
  23. mv $OUT/$i.new $OUT/$i
  24. else
  25. printf "$i (FAILED) "
  26. rm -f $OUT/$i.new
  27. fi
  28. done
  29. echo "Done."
  30. # Make sure committee can read 'em.
  31. #
  32. chmod 640 $OUT/*
  33. chgrp committe $OUT/*
  34. printf "Full dump: "
  35. $PG_DUMP > $USERDB_BACKUP
  36. echo "Done."