Periodically remove old recordings

This commit is contained in:
omidmaldar 2021-10-17 21:26:26 +03:00
parent 40db868ccd
commit 9a8825a73b
7 changed files with 98 additions and 16 deletions

View File

@ -258,6 +258,12 @@ services:
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- bigbluebutton:/var/bigbluebutton
tmpfs:
- /var/log/bigbluebutton
environment:
ENABLE_RECORDING: ${ENABLE_RECORDING}
REMOVE_OLD_RECORDING: ${REMOVE_OLD_RECORDING}
RECORDING_MAX_AGE_DAYS: ${RECORDING_MAX_AGE_DAYS}
networks:
bbb-net:
ipv4_address: 10.7.7.12

View File

@ -10,6 +10,8 @@ RUN apt-get update \
# -- install docker cli
COPY --from=library/docker:latest /usr/local/bin/docker /usr/bin/docker
COPY bbb-restart-kms bbb-resync-freeswitch entrypoint.sh /
COPY bbb-remove-old-recordings bbb-restart-kms bbb-resync-freeswitch entrypoint.sh /
RUN chmod +x bbb-remove-old-recordings
ENTRYPOINT ["/entrypoint.sh"]

View File

@ -0,0 +1,41 @@
#!/bin/bash
# Source: https://docs.bigbluebutton.org/admin/customize.html#delete-recordings-older-than-n-days
set -e
LOGFILE=/var/log/bigbluebutton/bbb-recording-cleanup-$(date --iso-8601='seconds' -u).log
shopt -s nullglob
NOW=$(date +%s)
echo "$(date --rfc-3339=seconds) Deleting recordings older than ${RECORDING_MAX_AGE_DAYS} days" >"${LOGFILE}"
# Find the name of recordings container in order to access `bbb-record` utility
BBB_RECORDINGS_CONTAINER_NAME=$(docker ps --filter "name=recordings" --filter "status=running" --format "{{.Names}}")
if [ $BBB_RECORDINGS_CONTAINER_NAME == "" ]; then
echo "$(date --rfc-3339=seconds) ERROR: recordings container is not running" >>"${LOGFILE}"
exit 1
fi
for donefile in /var/bigbluebutton/recording/status/published/*-presentation.done ; do
MTIME=$(stat -c %Y "${donefile}")
# Check the age of the recording
if [ $(( ( $NOW - $MTIME ) / 86400 )) -gt $RECORDING_MAX_AGE_DAYS ]; then
MEETING_ID=$(basename "${donefile}")
MEETING_ID=${MEETING_ID%-presentation.done}
echo "${MEETING_ID}" >> "${LOGFILE}"
docker exec "$BBB_RECORDINGS_CONTAINER_NAME" bbb-record --delete "${MEETING_ID}" >>"${LOGFILE}"
fi
done
for eventsfile in /var/bigbluebutton/recording/raw/*/events.xml ; do
MTIME=$(stat -c %Y "${eventsfile}")
# Check the age of the recording
if [ $(( ( $NOW - $MTIME ) / 86400 )) -gt $RECORDING_MAX_AGE_DAYS ]; then
MEETING_ID="${eventsfile%/events.xml}"
MEETING_ID="${MEETING_ID##*/}"
echo "${MEETING_ID}" >> "${LOGFILE}"
docker exec "$BBB_RECORDINGS_CONTAINER_NAME" bbb-record --delete "${MEETING_ID}" >>"${LOGFILE}"
fi
done

View File

@ -16,5 +16,10 @@ do
# delete presentations older than N days
find /var/bigbluebutton/ -maxdepth 1 -type d -name "*-*" -mtime +$history -exec rm -rf '{}' +
# delete recordings older than $RECORDING_MAX_AGE_DAYS
if [ "$ENABLE_RECORDING" == true ] && [ "$REMOVE_OLD_RECORDING" == true ]; then
/bbb-remove-old-recordings
fi
sleep 30m
done

View File

@ -34,6 +34,8 @@ ENABLE_GREENLIGHT=true
# https://github.com/bigbluebutton/bigbluebutton/issues/9202
# make sure that you get peoples consent, before they join a room
#ENABLE_RECORDING=true
#REMOVE_OLD_RECORDING=false
#RECORDING_MAX_AGE_DAYS=14
# ====================================
# SECRETS

View File

@ -38,6 +38,8 @@ docker run \
-v $(pwd)/docker-compose.tmpl.yml:/docker-compose.tmpl.yml \
-e DEV_MODE=${DEV_MODE:-false} \
-e ENABLE_RECORDING=${ENABLE_RECORDING:-false} \
-e REMOVE_OLD_RECORDING=${REMOVE_OLD_RECORDING:-false} \
-e RECORDING_MAX_AGE_DAYS=${RECORDING_MAX_AGE_DAYS:-14} \
-e ENABLE_HTTPS_PROXY=${ENABLE_HTTPS_PROXY:-false} \
-e ENABLE_WEBHOOKS=${ENABLE_WEBHOOKS:-false} \
-e ENABLE_COTURN=${ENABLE_COTURN:-false} \

View File

@ -72,6 +72,24 @@ while [[ ! $recording =~ ^(y|n)$ ]]; do
read -p "Choice (y/n): " recording
done
if [ "$recording" == "y" ]
then
remove_old_recording=""
while [[ ! $remove_old_recording =~ ^(y|n)$ ]]; do
read -p "Should old recordings be removed? (y/n): " remove_old_recording
done
if [ "$remove_old_recording" == "y" ]
then
recording_max_age_days=""
while [[ ! $recording_max_age_days =~ ^[0-9]{1,4}$ ]]; do
read -p "Please enter max age(days) for keeping recordings: " recording_max_age_days
done
fi
fi
ip_correct=""
while [[ ! $ip_correct =~ ^(y|n)$ ]]; do
read -p "Is $EXTERNAL_IPv4 your external IPv4 address? (y/n): " ip_correct
@ -124,6 +142,12 @@ then
sed -i "s/#ENABLE_RECORDING.*/ENABLE_RECORDING=true/" .env
fi
if [ "$remove_old_recording" == "y" ]
then
sed -i "s/#REMOVE_OLD_RECORDING=.*/REMOVE_OLD_RECORDING=true/" .env
sed -i "s/#RECORDING_MAX_AGE_DAYS=.*/RECORDING_MAX_AGE_DAYS=$recording_max_age_days/" .env
fi
if [ "$coturn" == "y" ]
then
sed -i "s/.*TURN_SERVER=.*/TURN_SERVER=turns:$DOMAIN:5349?transport=tcp/" .env