pruning script does not run (from domoticz wiki)

All kinds of 'OS' scripts

Moderator: leecollings

Post Reply
midomot
Posts: 20
Joined: Sunday 12 February 2017 13:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

pruning script does not run (from domoticz wiki)

Post 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
SweetPants

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

Post 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
midomot
Posts: 20
Joined: Sunday 12 February 2017 13:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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
franzelare
Posts: 141
Joined: Thursday 19 February 2015 21:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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...
midomot
Posts: 20
Joined: Sunday 12 February 2017 13:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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
franzelare
Posts: 141
Joined: Thursday 19 February 2015 21:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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....
theeuwes
Posts: 1
Joined: Saturday 30 November 2019 10:28
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10717
Contact:

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

Post by theeuwes »

Did anyone solve the problem in the pruning script? I got the same error message.
bxlouis
Posts: 45
Joined: Wednesday 16 December 2015 14:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Belgium
Contact:

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

Post 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.
plenkske
Posts: 5
Joined: Saturday 01 February 2020 15:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest