Page 1 of 1

pruning script does not run (from domoticz wiki)

Posted: Tuesday 05 September 2017 16:54
by midomot
Hello
I need some help troubleshooting a script

A while back (months ago) I used instructions from domoticz' wiki to setup nightly backup from my Pi to my Qnap
The script is from this page: https://www.domoticz.com/wiki/Daily_bac ... ternal_hdd
under section Script to backup to a Synology NAS

The backup is happening nightly, that is well.

However, I also appended, in same domoticz_backup.sh file, the "pruning' script, also from same page (just under the first script)
This part of the script has unfortunately never worked. Space is not an issue, but yeah.. I'd like it to work

I recently installed Notepad++, and opening the domoticz_backup.sh, it looks to me like it is showing errors towards the end
Lines 63 to 67. The unreadable smudges are just the LF.

If I run the script, I get new backup files, no error thrown.. The old backup files remain untouched

Image

Re: pruning script does not run (from domoticz wiki)

Posted: Wednesday 06 September 2017 13:09
by SweetPants
Next time, can you put the code in a code section?

Code: Select all

paste your code here
, makes it much more readable

Re: pruning script does not run (from domoticz wiki)

Posted: Wednesday 06 September 2017 13:22
by midomot
My bad, did not know about that possibility, you 're right, hard to read
the picture above shows where there might (?) be trouble
And here's the code, copied from my file but it really is code straight from domoticz's wiki
below I just XXXX'd my own data

Code: Select all

do#!/bin/bash
    # LOCAL/FTP/SCP/MAIL PARAMETERS
    SERVER="xxxx"  # IP of Synology NAS, used for ftp
    USERNAME="xxxx"         # FTP username of Network disk used for ftp
    PASSWORD="xxxx"         # FTP password of Network disk used for ftp
    DESTDIR="/opt/backup"   # used for temorarily storage
    DESTDIRNAS="/PiBackup/" # Path to your Synology NAS backup folder
    DOMO_IP="xxxx"   # Domoticz IP 
    DOMO_PORT="xxxx"        # Domoticz port 
    ### END OF USER CONFIGURABLE PARAMETERS
    TIMESTAMP=`/bin/date +%Y%m%d%H%M%S`
    BACKUPFILE="domoticz_$TIMESTAMP.db" # backups will be named "domoticz_YYYYMMDDHHMMSS.db.gz"
    BACKUPFILEGZ="$BACKUPFILE".gz
    ### Create backup and ZIP it
    /usr/bin/curl -s http://$DOMO_IP:$DOMO_PORT/backupdatabase.php > /tmp/$BACKUPFILE
    gzip -9 /tmp/$BACKUPFILE
    tar -zcvf /tmp/domoticz_scripts_$TIMESTAMP.tar.gz /home/pi/domoticz/scripts/
    tar -zcvf /tmp/telegram_scripts_$TIMESTAMP.tar.gz /home/pi/tg/scripts/
    ### Send to Network disk through FTP
    curl -s --disable-epsv -v -T"/tmp/$BACKUPFILEGZ" -u"$USERNAME:$PASSWORD" "ftp://$SERVER/$DESTDIRNAS"
    curl -s --disable-epsv -v -T"/tmp/domoticz_scripts_$TIMESTAMP.tar.gz" -u"$USERNAME:$PASSWORD" "ftp://$SERVER/$DESTDIRNAS"
    curl -s --disable-epsv -v -T"/tmp/telegram_scripts_$TIMESTAMP.tar.gz" -u"$USERNAME:$PASSWORD" "ftp://$SERVER/$DESTDIRNAS"
    ### Remove temp backup file
    /bin/rm /tmp/$BACKUPFILEGZ
    /bin/rm /tmp/domoticz_scripts_$TIMESTAMP.tar.gz
    /bin/rm /tmp/telegram_scripts_$TIMESTAMP.tar.gz
    ### Done!

# get a list of files and dates from ftp and remove files older than ndays
ftpsite="sftp -b-  -oPort=22  $USERNAME@$SERVER"
putdir=$DESTDIRNAS
 
ndays=19
 
# work out our cutoff date
MM=`date --date="$ndays days ago" +%b`
DD=`date --date="$ndays days ago" +%d`
TT=`date --date="$ndays days ago" +%s`
 
echo removing files older than $MM $DD
 
# get directory listing from remote source
echo "
cd $putdir
ls -l
"|$ftpsite >dirlist
 
# skip first three and last line, ftp command echo
listing="`tail -n+4 dirlist|head -n-1`"
 
lista=($listing)
 
# loop over our files
for ((FNO=0; FNO<${#lista[@]}; FNO+=9));do
  # month (element 5), day (element 6) and filename (element 8)
  # echo Date ${lista[`expr $FNO+5`]} ${lista[`expr $FNO+6`]}          File: ${lista[`expr $FNO+8`]}
 
  fdate="${lista[`expr $FNO+5`]} ${lista[`expr $FNO+6`]} ${lista[`expr $FNO+7`]}"
  sdate=`date --date="$fdate" +%s`
  # check the date stamp
  if [ $sdate -lt $TT ]
  then
      # Remove this file
      echo "$MM $DD: Removing  ${lista[`expr $FNO+5`]} /  ${lista[`expr $FNO+6`]} / ${lista[`expr $FNO+8`]}"
      $ftpsite <<EOMYF2
      cd $putdir
      rm ${lista[`expr $FNO+8`]}
      quit
EOMYF2
 
  fi
done

Re: pruning script does not run (from domoticz wiki)

Posted: Friday 02 February 2018 15:30
by franzelare
did you get this fixed? since i have the same issue.
when i only run the script from command prompt i get:
"Host Key verification failed"

what i see is that no password is given, but adding that doesn't do the trick...

Re: pruning script does not run (from domoticz wiki)

Posted: Friday 02 February 2018 15:51
by midomot
Ah... there I was, hoping someone could tell me what was wrong !

Nope, I gave up on the pruning script
The size of the files created is so small that I could not justify spending more time than I already had on trouble-shooting this

Re: pruning script does not run (from domoticz wiki)

Posted: Thursday 08 February 2018 14:19
by franzelare
midomot wrote: Friday 02 February 2018 15:51 Ah... there I was, hoping someone could tell me what was wrong !

Nope, I gave up on the pruning script
The size of the files created is so small that I could not justify spending more time than I already had on trouble-shooting this
my DB is >1GB so files are getting a bit big....

Re: pruning script does not run (from domoticz wiki)

Posted: Saturday 30 November 2019 10:31
by theeuwes
Did anyone solve the problem in the pruning script? I got the same error message.

Re: pruning script does not run (from domoticz wiki)

Posted: Sunday 15 December 2019 14:47
by bxlouis
I'm getting the same error, anyone knows how to fix this?
It would be great to update the Domoticz wiki with this.

Re: pruning script does not run (from domoticz wiki)

Posted: Monday 03 February 2020 9:37
by plenkske
Same here, the sftp command (deleting files part in the script) gives the error "host key verification failed"
Hope somebody could help us out.