Clearing Up Old Session Data

Clearing Up Old Session Data

Running the command

Connect to your server and run:

docker exec -ti backend node dist/scripts/session-clear-up.js

Command help

$ docker exec -ti backend node dist/scripts/session-clear-up.js --help
Options:
  --help         Show help                                             [boolean]
  --version      Show version number                                   [boolean]
  --dry-run                                           [boolean] [default: false]
  --session-id   Filter sessions by id                                  [string]
  --user-id      Filter sessions by user id                             [string]
  --months       Find sessions older than <value> months   [number] [default: 6]
  --output-type  Output type, csv or json, default value is csv [string] [default: csv]
  --output-file  Output file path, if you set a file path it will output to that file instead of stdout [string]
  --verbose, -v

Example output

info: Finding sessions older than 6 months (Wed Aug 14 2019 16:09:53 GMT+0000)
info: Found 2 sessions to delete

Are you sure you want to delete sessions? If you haven't taken a backup, please do so. Please type yes to confirm.

        Hint: Alternatively, use the --dry-run option to get an idea of what may be deleted

>

Backing up session zips prior to deletion

Retrieve the session IDs to back up
docker exec -ti backend node dist/scripts/session-clear-up.js --quiet --dry-run > session-ids
Copy the session zips to a target path
while read id; do
    echo "$id"
    docker exec -ti backend node dist/scripts/copy-zip-backup-file.js $id /tmp/$id.zip
done < session-ids
Delete the sessions

The --no-interaction option is available from v2.15.0.

while read id; do
    echo "$id"
    docker exec -ti backend node dist/scripts/session-clear-up.js --no-interaction --session-id $id
done < session-ids
Last updated on