HI Jbeale,
I tried leveraging your script to keep disk with at least some free by deleting old ones. However, it seems that my 30G card filled up after my trip.
The calendar archive function seems working fine.
Do you have any thoughts whether I got your script implemented correctly?
Thanks
[email protected]:~ $ crontab -l
15 * * * * sudo -u pi /home/pi/pikrellcam/scripts/pk-archive 2>&1 | /usr/bin/logger -t PK-Archive
[email protected]:~ $ cat /home/pi/pikrellcam/scripts/pk-archive
#!/bin/bash
_ARCHIVE_OLDER_DAYS="-1 Days" # how many days old for media before archiving
_VOLUME="/dev/sda1" # volume to check for disk space usage
#_VOLUME="/dev/root" # volume to check for disk space usage
_USED_SPACE_LIMIT=85 # percent disk space used over which files are deleted
echo "archive_still day `date --date="$_ARCHIVE_OLDER_DAYS" +'%F'`"
# Move _ARCHIVE_OLDER_DAYS stills and video to that date's archive folder
echo "archive_still day `date --date="$_ARCHIVE_OLDER_DAYS" +'%F'`" > /home/pi/pikrellcam/www/FIFO
echo "archive_video day `date --date="$_ARCHIVE_OLDER_DAYS" +'%F'`" > /home/pi/pikrellcam/www/FIFO
# if used space is over threshold, delete old files and directories to save storage space until threshold reached
# this keeps as much as possible files present
_USED_SPACE=`df | grep $_VOLUME | awk '{print $5}' | sed -e "s/\%//g"`
# echo "used space: $_USED_SPACE%"
if [[ ( "$_USED_SPACE" > "$_USED_SPACE_LIMIT" ) ]] ; then
echo -e "used space over $_USED_SPACE_LIMIT%, deleting old files..."
_LOOP=0;
while [[ ( "$_USED_SPACE" > "$_USED_SPACE_LIMIT" ) && ( "$_LOOP" < "100" ) ]] ; do
_OLDEST=`find /home/pi/pikrellcam/media/archive/ -type f -printf '%T+ %p\n' | sort | head -n 1 | cut -d "+" -f 1 | sed -e "s/\-/\//g"`
echo "oldest files:$_OLDEST"
echo "delete oldest folder:/home/pi/pikrellcam/media/archive/$_OLDEST"
rm -rfv "/home/pi/pikrellcam/media/archive/$_OLDEST"
sync
_USED_SPACE=`df | grep $_VOLUME | awk '{print $5}' | sed -e "s/\%//g"`
echo "used space now: $_USED_SPACE%"
_LOOP=$((_LOOP + 1))
done
echo "done"
df
else
echo -e "used space below $_USED_SPACE_LIMIT%, nothing to do!"
fi
[email protected]:~ $ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 1 28.9G 0 disk
└─sda1 8:1 1 28.9G 0 part /home/pi/pikrellcam/media
mmcblk0 179:0 0 7.4G 0 disk
├─mmcblk0p1 179:1 0 60M 0 part /boot
└─mmcblk0p2 179:2 0 7.3G 0 part /
[email protected]:~ $ ls -la /home/pi/pikrellcam/scripts
total 56
drwxr-xr-x 2 pi pi 4096 Aug 13 21:12 .
drwxr-xr-x 10 pi pi 4096 Aug 13 21:11 ..
-rwxr-xr-x 1 pi pi 1665 Apr 16 19:05 ds18b20.py
-rwxr-xr-x 1 pi pi 1463 Aug 13 21:12 example-motion-send-alarm1
-rwxr-xr-x 1 pi pi 3287 Aug 13 21:12 example-motion-send-alarm2
-rwxr-xr-x 1 pi pi 2335 Apr 30 18:03 motion-end
-rwxr-xr-x 1 pi pi 1800 Jul 14 20:07 pk-archive
-rwxr-xr-x 1 pi pi 2692 Aug 13 21:12 pkc-alarm
-rwxr-xr-x 1 pi pi 1757 Aug 13 21:12 pkc-motion
-rwxr-xr-x 1 pi pi 2093 Aug 13 21:12 pkc-reboot
-rwxr-xr-x 1 pi pi 647 Aug 13 21:12 pkc-recv
-rwxr-xr-x 1 pi pi 1827 Apr 23 12:47 preview-save
-rw-r--r-- 1 pi pi 436 Apr 16 19:05 Readme
-rwxr-xr-x 1 pi pi 1719 Jun 22 12:29 startup