Advertisement
chrissharp123

Untitled

Mar 1st, 2024
809
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.01 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. DB_HOST="db01"
  4. DB_USER="evergreen"
  5. PSQL="/usr/bin/psql"
  6. VACUUMDB="/usr/bin/vacuumdb"
  7. KEEP_ONE_YEAR="actor_usr_history"
  8. KEEP_SIX_MONTHS="actor_usr_address_history"
  9. KEEP_THREE_MONTHS="asset_call_number_history asset_copy_history biblio_record_entry_history"
  10.  
  11. INTERVAL="1 year"
  12. for table in $KEEP_ONE_YEAR; do
  13. $PSQL -U $DB_USER -h $DB_HOST -c "DELETE FROM auditor.$table WHERE audit_time < now() - '$INTERVAL'::interval"
  14. PGHOST=$DB_HOST PGUSER=$DB_USER $VACUUMDB --analyze --table auditor.$table
  15. done
  16.  
  17. INTERVAL="6 months"
  18. for table in $KEEP_SIX_MONTHS; do
  19. $PSQL -U $DB_USER -h $DB_HOST -c "DELETE FROM auditor.$table WHERE audit_time < now() - '$INTERVAL'::interval"
  20. PGHOST=$DB_HOST PGUSER=$DB_USER $VACUUMDB --analyze --table auditor.$table
  21. done
  22.  
  23. INTERVAL="3 months"
  24. for table in $KEEP_THREE_MONTHS; do
  25. $PSQL -U $DB_USER -h $DB_HOST -c "DELETE FROM auditor.$table WHERE audit_time < now() - '$INTERVAL'::interval"
  26. PGHOST=$DB_HOST PGUSER=$DB_USER $VACUUMDB --analyze --table auditor.$table
  27. done
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement