Announcement

Collapse
No announcement yet.

Automatic post compile backup

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Automatic post compile backup

    I'm a pretty disorganised guy, I often forget to backup. I wonder if anyone has a strategy for acheiving this?

    I've looked at several third party apps but nothing jumps out. I guess the best way would be to spoof the IDE by renaming PBWin.exe and creating a new PBWin.exe that rar'ed up everthing in the target directory and then chained to the renamed PBWin.exe.

    Alternately can anyone explain how to use the File Backup option in File Preferences, I tried several settings but nothing id saved. Perhaps I need to create a project?

  • #2
    In the IDE click on menu Window/Options/File
    In there you set the backup path (mine is ".\backup" and choose the other options you need.
    Every time you compile a backup of the source code is taken and put in the specified backup folder.

    Using projects is not required.

    Comment


    • #3
      Originally posted by Paul Dixon View Post
      In the IDE click on menu Window/Options/File
      In there you set the backup path (mine is ".\backup" and choose the other options you need.
      Every time you compile a backup of the source code is taken and put in the specified backup folder.

      Using projects is not required.
      Agree. Mine is ".\PBBack" since I occasionally use ".\backup" to back up data files etc used by an application.

      In particular, I would recommend selecting "with timestamp code".

      Comment


      • #4
        Interesting option; just tried it for the first time.

        Just wondering if anyone decodes the timestamp?

        Code:
        sRet =  DecodePBbackupstamp("1D522C61AFE9EA7")
        ? "sRet should =  2019-06-14 11:31:34"
        I haven't spent any time on it yet, and intend to play with it over the weekend.

        -John

        Comment


        • #5
          Looks like hex (nothing higher than F), 16 characters so 8 bytes. I'd guess a FILETIME in hex.

          Dale

          Comment


          • #6
            Did you allow for difference between local time and UTC, and difference between your watch and computer.
            Code:
            #compile exe
            #dim all
            #include "Win32API.inc"
            function pbmain () as long
              local TStamp as quad
              local TStampST as Systemtime
              local As_Str as string
              TStamp = val("&h1D522C61AFE9EA7&&") 'copied from post
              FiletimeToSystemTime(byval varptr(TStamp), TStampST)
              As_Str = dec$(TStampSt.wyear) + "-" + _
                       dec$(TStampSt.wmonth) + "-" + _
                       dec$(TStampSt.wday) + ", " + _
                       dec$(TStampSt.whour) + ":" + _
                       dec$(TStampSt.wminute) + ":" + _
                       dec$(TStampSt.wsecond) + "." + _
                       dec$(TStampSt.wmilliseconds, 3)  '<===edit, added ", 3"
              ? As_Str
              waitkey$ 'comment out for PBWin, leave for PBCC
            end function
            Because decode gives 2019-6-14, 15:30:32.906

            Cheers,
            Dale

            Comment


            • #7
              James,

              1) PowerBASIC can create a backup of every compile (as you know.)

              2) No other program needed to backup to another drive

              1-click backup
              Create shortcut to b.bat
              Only files that changed are backed up using /D.
              All folders could be backed up from the root, but /C (continue on error) would be needed in case a file can't be backed up.
              Replace d: below without second drive letter.
              If you prefer RoboCopy that is as an option.

              REM b.bat
              XCOPY /E/F/R/Y/D c:\folder1\*.* d:\folder1\*.*
              PAUSE



              I have 2 SSD's in machine and the second SSD is a clone of C (created using Macrium Reflect) https://www.macrium.com/reflectfree

              Optional: Second drive converted to "Windows To Go" so it can be booted on another machine if a hardware failure should occur.
              It is cool seeing everything you have running on another computer by using an external USB enclosure. USB boot works with "Windows To Go"
              My external StarTech.Com USB enclosure is dual drive and supports USB 3.1 Gen 2.
              It also has the ability to clone a drive to another drive without a computer.

              Free utility "WinToUSB"
              https://www.easyuefi.com/wintousb/index.html
              The option to Convert the Disk is under Tools and takes 1 or 2 seconds.
              It also takes 1 or 2 seconds to convert the disk back to a local disk (if ever needed.)

              If you have a portable SSD with USB interface like a Samsung T5 the external USB enclosure is not needed.
              I use "WinToUSB" on it and the drive can be externally booted from other computers.

              All software mentioned can be the free version or the paid version.
              https://duckduckgo.com instead of google

              Comment


              • #8
                Dale, I'm in NJ, so Eastern DST...

                I turned on the PBIDE backup and timestamp options, and got that 16-char string from the filename, then noted the timestamp on the file as shown by the OS...

                I have no experience adjusting times (I always struggle mightily with filetimes, systemtimes, and PowerTime objects... and avoid time zones like the plague!)

                Does it make sense for the PBIDE to set the code based on a time that's not the machine's local time?

                -John

                Comment


                • #9
                  Does it make sense for the PBIDE to set the code based on a time that's not the machine's local time?
                  Yes, it does. Windows keeps time as UTC. The time files are created, modified, etc are stored in UTC. Easier to set from time servers anywhere. file times (two words) can be compared regardless of zone, and UTC has no daylight savings adjustments. When you get a new computer (or Windows) and set the time (current local) then Windows displays the time and file times as local even though it keeps and stores as UTC. PB IDE uses Windows and there is an API to convert UTC FILETIME to Local FILETIME.

                  Current difference between UTC and Eastern is 4 hours, so that is what the time stamp is (hex of a current FILETIME). iPowerTime might help you with conversions.

                  Cheers,
                  Dale

                  Comment


                  • #10
                    Thanks Dale, excellent info!
                    -John

                    Comment


                    • #11
                      Here are a couple of useful functions to format the Date and Time strings whatever the locale of the system.
                      Code:
                      #Compile Exe
                      #Include "win32api.inc"
                      
                      %TestID = &h1D522C61AFE9EA7&&
                      '------------------/
                      
                      Function PBMain() As Long
                       Local TStamp As Quad
                       Local MyDateTime As SYSTEMTIME
                       Local FormDate, FormTime As String
                        TStamp = %TestID
                        FiletimeToSystemTime(byval varptr(TStamp), MyDateTime)
                      
                          FormDate = GetDate( MyDateTime, "yyyy-MM-dd")
                          FormTime = GetTime( MyDateTime, "HH:mm:ss")
                      
                        ? Using$("Date Time: &  & ~ From TimeStamp ID: & ", FormDate, FormTime, Hex$(TStamp))
                      
                      End Function
                      '------------------/PBMain
                      
                      Function GetDate (TheDate As SYSTEMTIME, TheMask As String) As String
                       Local zText As Asciiz * %MAX_PATH
                      
                          GetDateFormat (%LOCALE_USER_DEFAULT, _            ' Locale used for info not specified in mask
                                        0, _                                ' dwFlags
                                        ByVal VarPtr(TheDate), _            ' *lpDate (SystemTime)
                                        ByCopy TheMask, _                   ' lpFormat required date format
                                        zText, _                            ' out formatted Date string
                                        SizeOf(zText))                      ' cchDate
                      
                       Function = zText      '= Return Formated Date depending on the specified Date Mask.
                      End Function
                      '------------------/GetDate
                      
                      Function GetTime (TheTime As SYSTEMTIME, TheMask As String) As String
                        Local zText As Asciiz * %MAX_PATH
                      
                          GetTimeFormat (%LOCALE_USER_DEFAULT, _            ' Locale used for info not specified in mask
                                        0, _                                ' dwFlags
                                        ByVal VarPtr(TheTime), _            ' *lpTime (SYSTEMTIME)
                                        ByCopy TheMask, _                   ' lpFormat required time format
                                        zText, _                            ' out formatted Time string
                                        Sizeof(zText))                      ' cchTime
                      
                       Function = zText      '= Return Formated Time depending on the specified Time Mask.
                      End Function
                      '------------------/Get_Time
                      
                      #IF 0
                        ' TT Paul Squires: http://www.powerbasic.com/support/pbforums/showthread.php?t=040386
                      
                        Date Mask (Picture) Meaning:
                      
                        d      Day of month as digits with no leading zero for single-digit days.
                        dd     Day of month as digits with leading zero for single-digit days.
                        ddd    Day of week as a three-letter abbreviation. Function uses LOCALE_SABBREVDAYNAME value associated with specified locale.
                        dddd   Day of week as its full name. Function uses LOCALE_SDAYNAME value associated with specified locale.
                        M      Month as digits with no leading zero for single-digit months.
                        MM     Month as digits with leading zero for single-digit months.
                        MMM    Month as a three-letter abbreviation.  Function uses LOCALE_SABBREVMONTHNAME value associated with specified locale.
                        MMMM   Month as its full name. The Function uses the LOCALE_SMONTHNAME value associated with the specified locale.
                        y      Year as last two digits, but with no leading zero for years less than 10.
                        yy     Year as last two digits, but with leading zero for years less than 10.
                        yyyy   Year represented by full four digits.
                        gg     Period/era string A.C. B.C. The Function uses the CAL_SERASTRING value associated with the specified locale.
                               This element is ignored if the date to be formatted does not have an associated era or period string.
                      
                        Time Mask (Picture) Meaning
                        h      Hours with no leading zero for single-digit hours; 12-hour clock
                        hh     Hours with leading zero for single-digit hours; 12-hour clock
                        H      Hours with no leading zero for single-digit hours; 24-hour clock
                        HH     Hours with leading zero for single-digit hours; 24-hour clock
                        m      Minutes with no leading zero for single-digit minutes
                        mm     Minutes with leading zero for single-digit minutes
                        s      Seconds with no leading zero for single-digit seconds
                        ss     Seconds with leading zero for single-digit seconds
                        t      One character time marker string, such as A or P
                        tt     Multicharacter time marker string, such as AM or PM
                      
                      #ENDIF
                      Rgds, Dave

                      Comment


                      • #12
                        Click image for larger version  Name:	image_9885.png Views:	4 Size:	4.6 KB ID:	782050

                        "Numbered up to" works perfectly to (current folder or sub folder) or (all backups combined into any valid path folder)
                        As stated by Paul in Post #2.
                        https://duckduckgo.com instead of google

                        Comment


                        • #13
                          In post #11, Dave had use the time stamp of
                          %TestID = &h1D522C61AFE9EA7&& I can't figure out where can I get this time stamp ID from. Is it timestamp from a PB compile exe file?

                          Comment


                          • #14
                            I can't figure out where can I get this time stamp ID from. Is it timestamp from a PB compile exe file?

                            He copied it from your post #4, or maybe my post #6. I wouldn't call it an ID, but it does ID the date/time of a backup. It is a FILETIME in hex of when you did the source code save for your post #4 experiment. It is in the filename of the backup.

                            With 100nS units you will probably never see the same time stamp twice.

                            Cheers,
                            Dale

                            Comment


                            • #15
                              Well I must be doing something dim because I can't get it to work (both PBWin and CC). Guess I'll just have to remember.

                              Comment


                              • #16
                                Well I must be doing something dim because I can't get it to work (both PBWin and CC). Guess I'll just have to remember.

                                James,
                                Remember what, the source code?
                                Try going to a command prompt and switch to the Backup Path and type DIR BAC*.*
                                Sounds like you may be looking in the wrong folder or the GUI is hiding the files.


                                Would you please post a screen shot or tell us your settings?
                                I tried using an invalid drive and PowerBASIC displayed an error message while compiling.
                                Hopefully you are using a current version of PowerBASIC.

                                Click image for larger version  Name:	backup.png Views:	0 Size:	4.6 KB ID:	782060
                                https://duckduckgo.com instead of google

                                Comment


                                • #17
                                  I can't figure out where can I get this time stamp ID from. Is it timestamp from a PB compile exe file?
                                  Tim,

                                  In the PB IDE Options, I selected "with timestamp code", and the resulting PB IDE backed up the source file with a name that included the ID I provided. Each backup gets an ID based on date/time, and as shown in posts above, is encoded as a 16-character hex string.


                                  Dave,
                                  Thanks for the code in #11. I'll be experimenting with it this week.

                                  -John

                                  Comment


                                  • #18
                                    James,

                                    Try going to a command prompt and CD to the Backup Path and type DIR BAC*.*
                                    Sounds like you may be looking in the wrong folder or the GUI is hiding the files.
                                    What do you have in the Backup Path field?
                                    https://duckduckgo.com instead of google

                                    Comment


                                    • #19
                                      Thanks Dale and John, these timestamps are kinda hidden treasures

                                      Comment


                                      • #20
                                        James,

                                        The backup files are not written unless you compile (or manually save) a source code that has been modified.
                                        I kept re-compiling the same source over and over, while trying different settings without getting a backup file too.

                                        Finally I tried changing the source code (any simple change will do - eg delete a space ) and then I got something like "Backup.1D52355B5BFE858.Date Format.bas" in my nominated folder using the 'With timestamp code' option.
                                        Yipee!
                                        Rgds, Dave

                                        Comment

                                        Working...
                                        X