Make location of pihole log files configurable

Your guide works like a charm, as usual.
Here is the script I used to make the logs move to TMPFS:

#!/bin/bash

# pihole logs
# reference https://discourse.pi-hole.net/t/moving-the-pi-hole-log-to-another-location-device/2041
# add /var/www/html/slate7/pages/text to /etc/fstab
mkdir -p /var/log/pihole
sudo sed -i '$ a tmpfs /var/log/pihole tmpfs nodev,nosuid,gid=pihole,uid=pihole,mode=0755,size=16M 0 0' /etc/fstab
sudo mount /var/log/pihole

sudo service pihole-FTL stop
sudo cp /var/log/pihole.log /var/log/pihole
sudo rm /var/log/pihole.log
sudo cp /var/log/pihole-FTL.log /var/log/pihole
sudo rm /var/log/pihole-FTL.log
sudo ln -s /var/log/pihole/pihole.log /var/log/pihole.log
sudo ln -s /var/log/pihole/pihole-FTL.log /var/log/pihole-FTL.log
sudo service pihole-FTL start

# logrotate
mkdir -p /home/pi/custom-pihole
sudo cp /etc/pihole/logrotate /home/pi/custom-pihole
file=/home/pi/custom-pihole/logrotate
sudo sed -i 's#/var/log#/var/log/pihole#g' $file

# cron
echo "0 0 * * * root /usr/sbin/logrotate --force --state /var/log/pihole/status /home/pi/custom-pihole/logrotate" | sudo tee /etc/cron.d/custom-pihole
echo "@reboot root /usr/sbin/logrotate --state /var/log/pihole/status /home/pi/custom-pihole/logrotate" | sudo tee -a /etc/cron.d/custom-pihole

edit
modified the cron jobs, explanation, see next entry.
/edit

I used /home/pi/custom-pihole as the destination for the new logrotate to avoid conflicts with pihole -up and pihole -r

Thanks again for your time and effort.

2 Likes