GithubHelp home page GithubHelp logo

fredrikaverpil / tractor-purge Goto Github PK

View Code? Open in Web Editor NEW
4.0 5.0 4.0 34 KB

Purge jobs and task logs from Pixar's Tractor to avoid running out of disk space

License: MIT License

Python 100.00%
pixar pixar-tractor

tractor-purge's Introduction

tractor-purge

Purge command logs and/or delete/archive jobs from Pixar's Tractor to avoid running out of disk space.

How does this work?

This script is designed to be executed on the Tractor engine and must have write access to the command logs.

The script will find all jobs (including archived jobs) which do not have status active or ready and which are older than n days. It will then delete all associated command logs. If the --deletejobs option is given, the jobs will also be deleted from the database (or archived if DBArchiving is set to True in Tractor's db.config).

Please note, a separate facility provided by Pixar is available to purge jobs from the job archive database: tractor-dbctl --purge-archive-to-year-month YY-MM

Installation and execution of script

Put the file somewhere on the Tractor Engine, e.g:

$ git clone https://github.com/fredrikaverpil/tractor-purge.git /opt/tractor-purge

Check out the commandline options:

$ python tractor-purge.py --help

  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -t TQ, --tq=TQ        Absolute path to tq [default:
                        /opt/pixar/Tractor-2.2/bin/tq]
  -c CMDLOGSDIR, --cmd-log-sdir=CMDLOGSDIR
                        Absolute path to cmd-logs dir [default:
                        /var/spool/tractor/cmd-logs]
  -l LOGFILE, --log=LOGFILE
                        Absolute path to tractor-purge log file [default:
                        /var/tmp/tractor-purge.log]
  -d DAYS, --days=DAYS  Number of days worth of jobs/logs to keep [default:
                        30]
  --delete-cmd-logs     Delete cmd logs [default: False]
  --delete-jobs         Delete jobs from psql database after log deletion. If
                        DBArchiving is True in Tractor config, archive jobs
                        instead. [default: False]
  --dry-run             Do not perform actual deletion, instead just preview
                        deletions [default: False]

Example crontab on CentOS 7

This is how I run this script in conjunction with a jobs archive db purge on a nightly basis. I have DBArchiving set to True in my db.config.

  • Archive jobs with status "not active and not ready" which are older than 7 days
  • Delete command logs which are part of jobs older than 2 months
  • Purge archives database of jobs which are older than 2 months
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed
#

# Tractor Purge
#
# Remove cmd-logs for jobs which are older than 2 months:
  1  0 */1 *  * root python /opt/tractor-purge/tractor-purge.py --delete-cmd-logs --days=60
#
# Archive jobs older than 7 days which are "not active and not ready":
  5  0 */1 *  * root python /opt/tractor-purge/tractor-purge.py --delete-jobs --days=7
#
# Purge Tractor job archives database (keep 2 months worth of jobs):
#
# Year and month of today
YEAR=$((`date +%y`))
MONTH=$((`date +%m`))
#
# Get year and month from today minus 2 months
if [ $MONTH -eq 1 ]
then
    YEAR=$(($YEAR-1))
    MONTH=11
else
    MONTH=$(($MONTH-2))
fi
#
# Add padding to month
MONTH=`printf "%02d\n" $MONTH`
#
# Command (must run as the user executing tractor-engine), run every day
  0  0 */1 *  * tractoruser /opt/pixar/Tractor-2.2/bin/tractor-dbctl --purge-archive-to-year-month $YEAR-$MONTH --config-dir=/opt/pixar/config

tractor-purge's People

Contributors

fredrikaverpil avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.