Sto cercando di far mantenere i dati storici a questi due software presenti nei package di Luci, ma non ci riesco. Al riavvio /spegmnimento del router si azzerano sempre.

Ho inserito una usb e ho spostato la scittura dei dati su di essa.
Per Vnstat dal file vnstat.config e per nlbmon direttamnte dalla condifurazione gui Luci.

Dove sbaglio? Grazie

    Romarioele
    Lascia il db nella folder di default.
    Crea uno script vnstat_backup nella init.d e poi schedulalo anche via cron a intervalli regolari.
    Così fa dump ogni volta che lo stoppi correttamente e a intervalli.
    Poi quando parte in avvio fa restore in automatico.
    L'unico problema è che se ti muore male il router (tipo va via la corrente), perdi le statistiche dall'ultima esecuzione cron.
    Io ce l'ho ogni ora, al massimo perdo 59 minuti di statistiche se mi gira male.
    Se ti servono gli script te li giro.
    A memoria la ridirezione dati direttamente su usb non va perché il daemon viene su prima del disco esterno, ma non è detto che ricordi correttamente...

      10 giorni dopo

      Bender06

      mi potresti girare gli script? grazie

        Romarioele
        root@OWRT:~# cat /etc/init.d/vnstat_backup
        #!/bin/sh /etc/rc.common

        DATE=/bin/date +%Y-%m-%d_%H-%M-%S
        EXTRA_COMMANDS="backup restore"
        EXTRA_HELP=<<EOI
        backup Backup vnstat database
        restore Restore vnstat database
        EOI

        START=98
        STOP=10

        vnstat_option() {
        sed -ne "s/^[[:space:]]$1[[:space:]]['\"]([^'\"])['\"]./\1/p" /etc/vnstat.conf
        }

        BACKUP_FILE=/root/vnstat/vnstat_backup.tar.gz
        LOGGER_TAG=vnstat_backup
        VNSTAT_DIR="$(vnstat_option DatabaseDir)"

        backup_database() {
        if [ ! -d $VNSTAT_DIR ]; then
        logger -t $LOGGER_TAG -p err "cannot backup, data directory $VNSTAT_DIR does not exist (yet)"
        else
        logger -t $LOGGER_TAG -p info "backing up database"
        /bin/tar -zcf $BACKUP_FILE -C $VNSTAT_DIR .
        /bin/cp -rp /root/vnstat/vnstat_backup.tar.gz /usb/vnstat/vnstat_backup.$DATE.tar.gz
        fi
        }

        restore_database() {
        if [ ! -f $BACKUP_FILE ]; then
        logger -t $LOGGER_TAG -p err "cannot restore, backup file does not exist (yet)"
        else
        logger -t $LOGGER_TAG -p info 'restoring database'
        [ ! -d $VNSTAT_DIR ] && mkdir $VNSTAT_DIR
        /bin/tar -xzf $BACKUP_FILE -C $VNSTAT_DIR
        fi
        }

        start() {
        restore_database
        }

        stop() {
        backup_database
        }

        backup() {
        backup_database
        }

        restore() {
        restore_database
        }

        root@OWRT:~# crontab -l
        0 * * * * /etc/init.d/vnstat_backup backup

        Tieni presente che io salvo in local /root la copia corrente del dump, ma poi se guardi ne tengo una copia per data in /usb (mount point del disco usb3 esterno).
        Non la si usa in teoria, ma mi viene comodo aver copia esterna.

        grazie, provo

        10 giorni dopo
        12 giorni dopo

        Romarioele
        Alla cieca è un po' difficile aiutare.
        Posta un po' di comandi che hai lanciato e relativi output.

          6 giorni dopo

          Bender06
          quali comandi ho solo inserito lo script....

            Romarioele
            Ok, ma dove stai tentando di creare il backup e hai controllato i permessi di quel path?

              Bender06
              ho lasciato tutto come da default

              cat << "EOF" > /etc/init.d/vnstat_backup
              #!/bin/sh /etc/rc.common

              EXTRA_COMMANDS="backup restore"
              EXTRA_HELP=<<EOI
              backup Backup vnstat database
              restore Restore vnstat database
              EOI

              START=98
              STOP=10

              vnstat_option() {
              sed -ne "s/^[[:space:]]$1[[:space:]]['\"]([^'\"])['\"]./\1/p" /etc/vnstat.conf
              }

              BACKUP_FILE=/etc/vnstat_backup.tar.gz
              LOGGER_TAG=vnstat_backup
              VNSTAT_DIR="$(vnstat_option DatabaseDir)"

              backup_database() {
              if [ ! -d $VNSTAT_DIR ]; then
              logger -t $LOGGER_TAG -p err "cannot backup, data directory $VNSTAT_DIR does not exist (yet)"
              else
              logger -t $LOGGER_TAG -p info "backing up database"
              /bin/tar -zcf $BACKUP_FILE -C $VNSTAT_DIR .
              fi
              }

              restore_database() {
              if [ ! -f $BACKUP_FILE ]; then
              logger -t $LOGGER_TAG -p err "cannot restore, backup file does not exist (yet)"
              else
              logger -t $LOGGER_TAG -p info 'restoring database'
              [ ! -d $VNSTAT_DIR ] && mkdir $VNSTAT_DIR
              /bin/tar -xzf $BACKUP_FILE -C $VNSTAT_DIR
              fi
              }

              start() {
              restore_database
              }

              stop() {
              backup_database
              }

              backup() {
              backup_database
              }

              restore() {
              restore_database
              }
              EOF
              chmod +x /etc/init.d/vnstat_backup
              /etc/init.d/vnstat_backup enable

              Informativa privacy - Informativa cookie - Termini e condizioni - Regolamento - Disclaimer - 🏳️‍🌈
              P.I. IT16712091004 - info@fibraclick.it

              ♻️ Il server di questo sito è alimentato al 100% con energia rinnovabile