diff --git a/ansible/roles/common/templates/noaa-v2.conf.j2 b/ansible/roles/common/templates/noaa-v2.conf.j2 index dc755a4d..1b2355fb 100644 --- a/ansible/roles/common/templates/noaa-v2.conf.j2 +++ b/ansible/roles/common/templates/noaa-v2.conf.j2 @@ -24,3 +24,5 @@ NOAA_MAP_CROSSHAIR_COLOR={{ noaa_map_crosshair_color }} NOAA_MAP_GRID_DEGREES={{ noaa_map_grid_degrees }} NOAA_MAP_GRID_COLOR={{ noaa_map_grid_color }} PRODUCE_SPECTROGRAM={{ produce_spectrogram|lower }} +PRUNE_OLDER_THAN={{ delete_older_than_n }} +PRUNE_OLDEST={{ delete_oldest_n }} diff --git a/config/settings.yml.sample b/config/settings.yml.sample index 30e5e733..d127bba9 100644 --- a/config/settings.yml.sample +++ b/config/settings.yml.sample @@ -77,4 +77,10 @@ log_level: DEBUG # by default disabled on "extra-small" devices such as phones due to # the processing and space requirements enable_satvis: true + +# pruning capabilities - must be configured in cron (see documentation) +# delete_oldest_n - how many oldest captures to delete on each run +# delete_older_than_n - delete all images older than this many days +delete_oldest_n: 0 +delete_older_than_n: 0 ... diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 9ca4a7dd..23816c48 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -73,13 +73,33 @@ Audio may not exist depending on how you configured your installation. By defaul after images are created to preserve space on your Raspberry Pi. If you disabled deleting audio, the audio should obviously still remain in its directory after image processing completes. -In addition, there is an ability to "prune" images to maintain space on your Raspberry Pi, deleting the 10 oldest images -from the disk and the database. Note that this is a destructive operation that is non-recoverable, so be certain this is -what you want to be doing. If so, run the following command, which will configure the prune script to run each day at -midnight: +In addition, there is an ability to "prune" images to maintain space on your Raspberry Pi. This can be done one of 2 ways, +detailed below. In either case, to adjust the configurations for these, update the respective parameter in the `config/settings.yml` +file and re-run the `install_and_upgrade.sh` script to propagate your settings *BEFORE* creating the cron jobs. + +**NOTE**: Both of these prune scripts delete the associated files and database records for the captures that are in scope. +Make sure this is what you want as once the script has run and the captures are deleted, they will not be recoverable. + +## Prune Oldest n Captures + +This script, named `scripts/prune_scripts/prune_oldest.sh`, is used to prune the oldest `n` number of captures, where `n` is +configured as the `delete_oldest_n` parameter in `config/settings.yml`. This is an example of a cron job that is +configured to run nightly at midnight using this script: + +```bash +# prune oldest n captures +cat <(crontab -l) <(echo "1 0 * * * /home/pi/raspberry-noaa-v2/scripts/prune_oldest.sh") | crontab - +``` + +## Prune Captures Older Than n Days + +This script, named `scripts/prune_scripts/prune_older_than.sh`, is used to prune all captures older than `n` days old, where +`n` is configured as the `delete_older_than_n` parameter in `config/settings.yml`. This is an example of a cron job +that is configured to run nightly at midnight using this script: ```bash -cat <(crontab -l) <(echo "1 0 * * * /home/pi/raspberry-noaa-v2/scripts/prune.sh") | crontab - +# prune captures older than n days +cat <(crontab -l) <(echo "1 0 * * * /home/pi/raspberry-noaa-v2/scripts/prune_older_than.sh") | crontab - ``` # Completely White Meteor-M 2 Images diff --git a/scripts/prune_scripts/prune_older_than.sh b/scripts/prune_scripts/prune_older_than.sh new file mode 100755 index 00000000..33279842 --- /dev/null +++ b/scripts/prune_scripts/prune_older_than.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# +# Purpose: Prunes (removes) all captures older than $PRUNE_OLDER_THAN days old, including +# database records and associated images/files on disk. + +# import common lib and settings +. "$HOME/.noaa-v2.conf" +. "$NOAA_HOME/scripts/common.sh" + +#Generate date since epoch in seconds - days +let prunedate=$(date +%s)-$PRUNE_OLDER_THAN*24*60*60 + +log "Pruning captures..." "INFO" +for img_path in $(sqlite3 ${DB_FILE} "select file_path from decoded_passes where pass_start < $prunedate;"); do + find "${IMAGE_OUTPUT}/" -maxdepth 1 -type f -name "${img_path}*.jpg" exec rm -f {} \; + find "${IMAGE_OUTPUT}/thumb/" -maxdepth 1 -type f -name "${img_path}*.jpg" exec rm -f {} \; + log " ${img_path} file pruned" "INFO" + sqlite3 "${DB_FILE}" "delete from decoded_passes where file_path = \"$img_path\";" + log " Database entry pruned" "INFO" +done diff --git a/scripts/prune.sh b/scripts/prune_scripts/prune_oldest.sh similarity index 50% rename from scripts/prune.sh rename to scripts/prune_scripts/prune_oldest.sh index b583e1a8..62b04b05 100755 --- a/scripts/prune.sh +++ b/scripts/prune_scripts/prune_oldest.sh @@ -1,16 +1,16 @@ #!/bin/bash # -# Purpose: Prunes (removes) the 10 oldest captures from the database -# and respective images. +# Purpose: Prunes (removes) the $PRUNE_OLDEST number of oldest captures, including +# database records and associated images/files on disk. # import common lib and settings . "$HOME/.noaa-v2.conf" . "$NOAA_HOME/scripts/common.sh" log "Pruning captures..." "INFO" -for img_path in $(sqlite3 ${DB_FILE} "select file_path from decoded_passes limit 10;"); do - find "${IMAGE_OUTPUT}/" -type f -name "${IMG_NAME}*.jpg" -exec rm -f {} \; - find "${IMAGE_OUTPUT}/thumb/" -type f -name "${IMG_NAME}*.jpg" -exec rm -f {} \; +for img_path in $(sqlite3 ${DB_FILE} "select file_path from decoded_passes limit ${PRUNE_OLDEST};"); do + find "${IMAGE_OUTPUT}/" -maxdepth 1 -type f -name "${img_path}*.jpg" exec rm -f {} \; + find "${IMAGE_OUTPUT}/thumb/" -maxdepth 1 -type f -name "${img_path}*.jpg" exec rm -f {} \; log " ${img_path} file pruned" "INFO" sqlite3 "${DB_FILE}" "delete from decoded_passes where file_path = \"$img_path\";" log " Database entry pruned" "INFO"