MoinMoin Logo
  • Kommentare
  • Geschützte Seite
  • Menu
    • Navigation
    • AktuelleÄnderungen
    • SeiteFinden
    • ÜbersichtsKarte
    • Help
    • HilfeInhalt
    • HilfeZurMoinWikiSyntax
    • Anzeige
    • Dateianhänge
    • Info
    • Rohform
    • Druckansicht
    • Editieren
    • Laden
    • Speichern
  • Anmelden

Navigation

  • AktuelleÄnderungen
  • SeiteFinden
  • HilfeInhalt
Revision 21 vom 2020-11-17 15:38:41
  • Raspberry SD-Karte schonen

Raspberry SD-Karte schonen

/var/log in eine RAMDisk auslagern:

In die /etc/fstab schreiben:

tmpfs /var/log tmpfs defaults,noatime,nosuid,mode=0755,size=50M 0 0
tmpfs /tmp tmpfs defaults,noatime,nosuid,mode=0755,size=50M 0 0

Danach: reboot

Jetzt noch das varlog-Script aus diesem Thread umsetzen! (Siehe Dateianhänge an dieser Seite)

mkdir /var/archive
apt-get -y install rsync

echo "SystemMaxUse=50M" | sudo tee -a /etc/systemd/journald.conf
echo "SystemKeepFree=5M" | sudo tee -a /etc/systemd/journald.conf
echo "SystemMaxFileSize=4M" | sudo tee -a /etc/systemd/journald.conf
echo "ForwardToSyslog=no" | sudo tee -a /etc/systemd/journald.conf

mkdir -p /var/log/journal
systemd-tmpfiles --create --prefix /var/log/journal
systemctl restart systemd-journald
apt-get purge --remove rsyslog
adduser hss systemd-journal

reboot

# Ein paar Tests:
df -Th | grep tmpfs
rm /var/log/messages
rm /var/log/syslog
journalctl


cat >> /etc/logrotate_varlog.conf << "EOFCONF"
# see "man logrotate" for details
# rotate log files weekly
#daily

# keep 4 weeks worth of backlogs
rotate 7

# create new (empty) log files after rotating old ones
create

# uncomment this if you want your log files compressed
compress

# Logs are moved into directory for rotation
olddir /var/archive

# packages drop log rotation information into this directory
#include /etc/logrotate.d

/var/log_save/journal/8c5604e85c924195aef34a3e4079998d/system.journal {
    missingok
    notifempty
}

# system-specific logs may be configured here

EOFCONF

cat >> /etc/systemd/system/logrotate.service << "EOFSVC"
[Unit]
Description=Rotate log files
Documentation=man:logrotate(8) man:logrotate.conf(5)
ConditionACPower=true

[Service]
Type=oneshot
ExecStart=/usr/sbin/logrotate /etc/logrotate_varlog.conf
Nice=19
IOSchedulingClass=best-effort
IOSchedulingPriority=7

EOFSVC


cat >> /etc/systemd/system/logrotate.timer << "EOFTIMER"
[Unit]
Description=Daily rotation of log files
Documentation=man:logrotate(8) man:logrotate.conf(5)

[Timer]
OnBootSec=2min
Unit=logrotate.service

[Install]
WantedBy=timers.target

EOFTIMER


cat >> /etc/systemd/system/varlog.service << "EOFSERVICE"
[Unit]
Description=varlog.service:  Redirect /var/log to tmpfs
DefaultDependencies=no
Before=local-fs.target shutdown.target
Conflicts=umount.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/varlog start
ExecStop=/usr/local/bin/varlog stop

[Install]
RequiredBy=systemd-journal-flush.service

EOFSERVICE


cat >> /usr/local/bin/sik.sh << "EOFSIK"
#!/bin/bash
# Ein system.journal aus einer mit gz gepackten Datei wieder herstellen. Aufruf im varlog sik Zweig.

if [ -f /var/archive/system.journal ]; then

echo -e "\t\033[1;31m"
echo "**************************************************************************************************"
echo  "* In /var/archive/ ist ein system.journal vorhanden es muss mit y gelöscht werden."
echo "**************************************************************************************************"
echo -e "Ihre Eingabe:\t\033[1;31m\c"; read wahl

echo "Datei wird gelöscht"
sleep 2
rm /var/archive/system.journal
reset
fi

auswahl=$(ls -X /var/archive/ | grep -i -e \. | cut -d. -f 3)
echo -e "\033[1;32m"
echo "**************************************************************************************************"
echo -e "* Folgende system.journal.x.gz Dateien wurden im Ordner /var/archive/ gefunden.\n\t"$auswahl
echo "* Bitte die gewünschte Datei Nummer (1...7) eingeben. Weiter mit <ENTER>"
echo "**************************************************************************************************"
read wn
sleep 2

gunzip /var/archive/system.journal.$wn.gz
sleep 2
mv /var/archive/system.journal.$wn /var/archive/system.journal
sleep 2
echo "**************************************************************************************************"
echo "* Das system.journal wird mit journalctl --verify -D geprüft."
echo "**************************************************************************************************"
journalctl --verify -D /var/archive/
sleep 3
echo -e "\033[1;32m"
echo "**************************************************************************************************"
echo "* Das system.journal wird mit journalctl -p err auf Fehler geprüft."
echo "**************************************************************************************************"
journalctl -p err -D /var/archive/
sleep 3
echo -e "\033[1;32m"
echo "**************************************************************************************************"
echo "* Mal sehen was von varlog so in das Journal geschrieben wurde."
echo "**************************************************************************************************"
reset
journalctl --file=/var/archive/system.journal | grep "varlog\|journal" -i
sleep 3
echo -e "\033[1;32m"
echo "**************************************************************************************************"
echo "* Das system.journal wird mit journalctl --file=... komplett angezeigt Bitte mit q = Quit Beenden."
echo "**************************************************************************************************"
journalctl --file=/var/archive/system.journal
reset

EOFSIK



cat >> /usr/local/bin/varlog << "EOFVARLOG"
#!/bin/bash

case $1 in
    start)
        echo "*** Start von varlog File restore:"
        /bin/mount -t tmpfs tmpfs /var/log -o defaults,size=55M
        /bin/chmod 755 /var/log
        /usr/bin/rsync -a --exclude "- *.journal" --delete /var/log_save/ /var/log/
        echo 'Der Start Zweig von varlog wurde Beendet' | systemd-cat -t varlog -p info
    ;;
    stop)
        echo "*** Stop von varlog File saving:"
        /bin/mkdir -p /var/log_save
        /usr/bin/rsync -a --exclude "**~" --exclude "- user*" --delete /var/log/ /var/log_save/ > /dev/null
        /bin/sync
        #umount -f /var/log/
        echo 'Der Stop Zweig von varlog wurde Beendet' | systemd-cat -t varlog -p info
    ;;
    sik)
        echo "*** Start von varlog sik erfolgreich."
        /usr/local/bin/sik.sh
        echo 'Der Sik Zweig von varlog wurde Beendet' | systemd-cat -t varlog -p info
    ;;
    daily)
       echo "*** Start vom varlog Daily Zweig:"
       /usr/bin/rsync -a --exclude "**~" --exclude "- user*" --exclude "- system@*" --delete /var/log/ /var/log_save/ > /dev/null
       /bin/sync
       sleep 2
       /usr/sbin/logrotate /etc/logrotate_varlog.conf
       sleep 2
       rm /var/log/journal/8c5604e85c924195aef34a3e4079998d/system@*
       echo 'Der Daily Zweig von varlog wurde Beendet' | systemd-cat -t varlog -p info
   ;;
esac

exit 0

EOFVARLOG


cat >> /etc/systemd/system/logrotate-daily.timer << "EOFDAILY"
[Unit]
Description=daily rotation der log files mit varlog
Documentation=man:logrotate(8) man:logrotate.conf(5)


[Timer]
OnCalendar=daily
RandomizedDelaySec=10
Persistent=true


[Install]
WantedBy=basic.target

EOFDAILY


cat >> /etc/systemd/system/logrotate-daily.service << "EOFDAYSVC"
[Unit]
Description=logrotate-daily.service


[Service]
ExecStart=/usr/local/bin/varlog daily


EOFDAYSVC

Swap abschalten:

systemctl disable dphys-swapfile


KategorieRaspberry

  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01