Rpi : persitent manger and create backup/restore files on usb

galexis
2020-06-05
2020-06-10
  • galexis - 2020-06-05

    In the past, I use a SD card with Rpi3B and a code to save persistents variables on files with a button and automatically restore persistents at boot.

    PROGRAM MEMORISATION_PERSISTANTS
    
    VAR
        fbDelete            : FILE.Delete; (* bloc pour effacer le contenu du fichier *) 
        sFileName           : STRING := 'data.ret';
        pApp                : POINTER TO APPLICATION;
        Result              : RTS_IEC_RESULT;
        xInit               : BOOL;
        RESTORE: bool;
    END_VAR
    
    //CmpApp + CAA File + SysTypes Interfaces
    IF NOT xInit THEN
       pApp := AppGetCurrent(pResult:=ADR(Result));
       xInit := TRUE;
       RESTORE:=TRUE;
       PERSIST_RESTAUREES:=FALSE;
    END_IF
    
    IF SAUVEGARDER=TRUE AND NOT RESTORE THEN   
       (* En premier effacer le fichier.
          car la fonction AppStoreRetainsInFile ajoute les donnΓ©es Γ  la suite du fichier. *)
       fbDelete(xExecute:=TRUE, sFileName:=sFileName);
       IF fbDelete.xDone OR (fbDelete.xError AND fbDelete.eError = File.Error.NOT_EXIST) THEN
          fbDelete(xExecute:=FALSE);
          SAUVEGARDER:=FALSE;
          (* enregister. *)
          IF pApp <> 0 THEN
             Result := AppStoreRetainsInFile(pApp,sFileName);
          END_IF
       END_IF
    END_IF
    
    (* Restaurer les data depuis le fichier.*)
    IF RESTORE THEN
       Result := AppRestoreRetainsFromFile(pApp, sFileName);
       RESTORE := FALSE;
       PERSIST_RESTAUREES:=TRUE;
    END_IF
    

    It work fines and I use same code to make backup/restore on USB card.

    Now, Rpi work on SSD , not yet on SD. I use other method for persistents on SSD : "persistence manager". How to here: https://forge.codesys.com/forum/en/4275/genmed-How%20to%20Setup%20the%20PersistenceManager%20from%20Scratch.pdf
    This method work well, but I would like to make additionnal backup and restore to USB card, but with the old method, persistents aren't restore and I'm not sure backup files was good....
    Persitents variables are still in "persistentVars". I add this before each variables:

    {attribute 'ac_persist':='PersistenceChannel'}
    

    Could you help me?

     

    Last edit: galexis 2020-06-05
  • Ingo

    Ingo - 2020-06-08

    Hi Galexis,

    to me your code looks good. I think I didn't get the question. Your approach should work independently of the filesystem that is used, right!?

     
  • galexis - 2020-06-10

    The files is store on path /PlcLogic/ac_perstitence. I could make copy on usb key but how to restore it after ? If I write it on /PlcLogic/ac_perstitence it should be work ? Any command to activate to load this files on memory ?

     

Log in to post a comment.