sauvegarde vdd domoticz sur NAS

Forum dédié aux questions concernant la configuration de votre serveur sous Linux
vr6man
Messages : 627
Inscription : 18 juil. 2017, 12:15

sauvegarde vdd domoticz sur NAS

Message par vr6man »

Bonjour j'ai vu ce tuto pour copier les sauvegardes sur un Synology

https://www.domoticz.com/wiki/Daily_bac ... ternal_hdd

Code : Tout sélectionner

 #!/bin/bash
    # LOCAL/FTP/SCP/MAIL PARAMETERS
    SERVER="192.168.1.250"   # IP of Network disk, used for ftp
    USERNAME="xxx"         # FTP username of Network disk used for ftp
    PASSWORD="xxxx"         # FTP password of Network disk used for ftp
    DESTDIR="/Raspberry"   # used for temorarily storage
    DOMO_IP="192.168.1.251"  # Domoticz IP 
    DOMO_PORT="8080"        # 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, ZIP it and start Domoticz again
    /usr/bin/curl -s http://$DOMO_IP:$DOMO_PORT/backupdatabase.php > /tmp/$BACKUPFILE
    gzip -9 /tmp/$BACKUPFILE
    ### Send to Network disk through FTP
    curl -s --disable-epsv -v -T"/tmp/$BACKUPFILEGZ" -u"$USERNAME:$PASSWORD" "ftp://$SERVER/media/hdd/Domoticz_backup/"				
    ### Remove temp backup file
    /bin/rm /tmp/$BACKUPFILEGZ
    ### Done!
j'ai un message d'erreur quand je le lance

Code : Tout sélectionner

* Expire in 0 ms for 6 (transfer 0x16c9960)
*   Trying 192.168.1.250...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x16c9960)
* Connected to 192.168.1.250 (192.168.1.250) port 21 (#0)
< 220 Nas_home FTP server ready.
> USER xxxx
< 331 Password required for admin.
> PASS xxxx
< 230 User admin logged in.
> PWD
< 257 "/" is current directory.
* Entry path is '/'
> CWD media
* ftp_perform ends with SECONDARY: 0
< 550 No such file or directory.
* Server denied you to change to the given directory
* Uploaded unaligned file size (0 out of 109 bytes)
* Connection #0 to host 192.168.1.250 left intact
Apparement il n'arrive pas a écrire dans le répertoire pourtant celui à les doits en écriture

A votre avis ?
Keros
Messages : 6638
Inscription : 23 juil. 2019, 20:57

Re: sauvegarde vdd domoticz sur NAS

Message par Keros »

Est-ce que tu as essayé de créer ou copier un fichier sur le NAS depuis l'OS hébergeant DomoticZ ?
Comment bien utiliser le forum : Poser une question, Mettre un script, un fichier, une image ou des logs
Mes petits guides : Débuter en programmation, Le débogage, Le choix de matériel, Les sauvegardes
Ma présentation - Mes Tutos
vr6man
Messages : 627
Inscription : 18 juil. 2017, 12:15

Re: sauvegarde vdd domoticz sur NAS

Message par vr6man »

non

quel commande je peux lancer pour faire ce test car je suis pas un spécialiste

merci
Keros
Messages : 6638
Inscription : 23 juil. 2019, 20:57

Re: sauvegarde vdd domoticz sur NAS

Message par Keros »

Je n'ai pas de commande sous la main. Je pense que tu devrais en trouver sur Internet en fonction de ton OS.
Cela devrait t'aider à déterminer si la configuration du NAS est bonne ou pas.
Comment bien utiliser le forum : Poser une question, Mettre un script, un fichier, une image ou des logs
Mes petits guides : Débuter en programmation, Le débogage, Le choix de matériel, Les sauvegardes
Ma présentation - Mes Tutos
vr6man
Messages : 627
Inscription : 18 juil. 2017, 12:15

Re: sauvegarde vdd domoticz sur NAS

Message par vr6man »

la config du n'as semble bonne car il se connecte bien c'est apparemment un problème d'écriture

Par contre j'ai regardé sur google et je vois pas trop
vr6man
Messages : 627
Inscription : 18 juil. 2017, 12:15

Re: sauvegarde vdd domoticz sur NAS

Message par vr6man »

bon j'ai trouvé c'était le chemin qui posait problème c'est réglé

Par contre quand je souhaite ajouter le code suivant récupérer sur le wiki afin de purger régulièrement le NAS

Code : Tout sélectionner

# 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

J'ai le message d'erreur suivant sur cette partie du script:

Code : Tout sélectionner

* Connection #0 to host 192.168.1.250 left intact
removing files older than fév 22
Host key verification failed.
Connection closed
/home/pi/domoticz/scripts/domoticz_backup.sh: 52: /home/pi/domoticz/scripts/domoticz_backup.sh: Syntax error: "(" unexpected
Keros
Messages : 6638
Inscription : 23 juil. 2019, 20:57

Re: sauvegarde vdd domoticz sur NAS

Message par Keros »

Tu peux nous mettre ton script domoticz_backup.sh en entier. Il semblerait que tu aies une erreur avec une "(" à la ligne 52. Et il n'y a que 44 lignes dans le code que tu as passé.
Comment bien utiliser le forum : Poser une question, Mettre un script, un fichier, une image ou des logs
Mes petits guides : Débuter en programmation, Le débogage, Le choix de matériel, Les sauvegardes
Ma présentation - Mes Tutos
vr6man
Messages : 627
Inscription : 18 juil. 2017, 12:15

Re: sauvegarde vdd domoticz sur NAS

Message par vr6man »

voila

LA sauvegarde et l'export sur le nas se fait bien c'est la deuxième partie du script dans le tutoriel (la partie purge) qui semble poser problème

Code : Tout sélectionner

#!/bin/bash
    # LOCAL/FTP/SCP/MAIL PARAMETERS
    SERVER="192.168.1.250"  # 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="/tmp"   # used for temorarily storage
    DESTDIRNAS="/Raspberry/rasphome/Sauvegarde/Database Domoticz/" # Path to your Synology NAS backup folder
    DOMO_IP="192.168.1.251"   # Domoticz IP 
    DOMO_PORT="8080"        # 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/
    ### 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"
    ### Remove temp backup file
    /bin/rm /tmp/$BACKUPFILEGZ
    /bin/rm /tmp/domoticz_scripts_$TIMESTAMP.tar.gz
    
    # 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

    ### Done!
Répondre