Autobackup from Navision Client (not NAS)

garakgarak Member Posts: 3,263
edited 2012-02-22 in NAV Tips & Tricks
If you need to create an backup (*.fbk) from the Navision client automaticly, for example at 10:00pm you can use following form / the functions in this form.
Note, that this is an example for working with WSH.
OBJECT Form 59003 Checklist Make Navision Backup
{
  OBJECT-PROPERTIES
  {
    Date=12.10.07;
    Time=16:46:29;
    Modified=Yes;
    Version List=EXP-GesNeuAnalge;
  }
  PROPERTIES
  {
    Width=10890;
    Height=3410;
    CaptionML=[DEU=Checkliste Datensicherungserstellung;
               ENU=Checklist Make Navision Backup];
    OnOpenForm=BEGIN
                 //01 EXP - RKA +
                 Description := STRSUBSTNO(Text0002,COMPANYNAME,TODAY);
                 CurrForm.txtFilename.ACTIVATE();
                 //01 EXP - RKA -
               END;

  }
  CONTROLS
  {
    { 1   ;CommandButton;6050 ;2640 ;2200 ;550  ;HorzGlue=Right;
                                                 VertGlue=Bottom;
                                                 CaptionML=[DEU=&Erstellen;
                                                            ENU=Create Backup];
                                                 OnPush=VAR
                                                          i@1001 : Integer;
                                                        BEGIN
                                                          //01 EXP - RKA +
                                                          IF (Description = '') THEN
                                                            Description := STRSUBSTNO(Text0002,COMPANYNAME,TODAY);

                                                          IF (Filename = '') OR (Filename = STRSUBSTNO(Text0002,COMPANYNAME,TODAY)) THEN
                                                            ERROR(Text0003);

                                                          IF ISCLEAR(WSHShell) THEN
                                                            CREATE(WSHShell);

                                                          IF ISCLEAR(Timer) THEN
                                                            CREATE(Timer);

                                                          Timer.Interval(10);
                                                          Timer.Enabled(TRUE);
                                                          //01 EXP - RKA -
                                                        END;
                                                         }
    { 3   ;Frame        ;220  ;880  ;10450;1540 ;HorzGlue=Both;
                                                 VertGlue=Both;
                                                 ShowCaption=No }
    { 4   ;TextBox      ;3850 ;1100 ;6600 ;440  ;HorzGlue=Both;
                                                 ParentControl=3;
                                                 InFrame=Yes;
                                                 CaptionML=[DEU=Beschreibung;
                                                            ENU=Description];
                                                 SourceExpr=Description }
    { 5   ;Label        ;440  ;1100 ;3300 ;440  ;ParentControl=4 }
    { 6   ;TextBox      ;3850 ;1760 ;6600 ;440  ;Name=txtFilename;
                                                 HorzGlue=Both;
                                                 ParentControl=3;
                                                 InFrame=Yes;
                                                 CaptionML=[DEU=Dateiname;
                                                            ENU=Filename];
                                                 SourceExpr=Filename;
                                                 OnAssistEdit=BEGIN
                                                                //01 EXP - RKA +
                                                                Filename := CMDMgmt.OpenFile(Text0001,STRSUBSTNO(Text0002,COMPANYNAME,TODAY) + '.fbk',4,'*.fbk',1);
                                                                IF (STRPOS(Filename,':\') = 0) THEN
                                                                  Filename := '';
                                                                //01 EXP - RKA -
                                                              END;
                                                               }
    { 7   ;Label        ;440  ;1760 ;3300 ;440  ;ParentControl=6 }
    { 2   ;CommandButton;8470 ;2640 ;2200 ;550  ;HorzGlue=Right;
                                                 VertGlue=Bottom;
                                                 PushAction=FormHelp;
                                                 CaptionML=DEU=&Hilfe }
    { 8   ;Label        ;220  ;0    ;10450;770  ;HorzGlue=Both;
                                                 VertGlue=Top;
                                                 HorzAlign=Center;
                                                 ForeColor=3368703;
                                                 FontSize=15;
                                                 FontBold=Yes;
                                                 LeaderDots=No;
                                                 CaptionML=[DEU=GARAK - Navision Datensicherung;
                                                            ENU=GARAK - Navision Backup] }
  }
  CODE
  {
    VAR
      CMDMgmt@1001 : Codeunit 412;
      WSHShell@1000 : Automation "{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} 1.0:{72C24DD5-D70A-438B-8A42-98424B88AFB8}:'Windows Script Host Object Model'.WshShell";
      Timer@1003 : Automation "{3B311C81-140E-11D5-8B18-00D0590B4EC5} 1.0:{3B311C92-140E-11D5-8B18-00D0590B4EC5}:'Navision Timer 1.0'.Timer" WITHEVENTS;
      ShellIsSend@1005 : Boolean;
      ShellIsSend2@1006 : Boolean;
      Description@1007 : Text[50];
      Filename@1008 : Text[1024];
      Text0001@1002 : TextConst 'DEU=Backup speichern;ENU=Backup save.';
      Text0002@1009 : TextConst 'DEU=Backup %1 vom %2;ENU=Backup %1 by %2';
      Text0003@1010 : TextConst 'DEU=Dateiname ist anzugeben;ENU=Fill out filename';
      Text0004@1000000000 : TextConst 'DEU=%xs;ENU=%tb';

    EVENT Timer@1003::Timer@1(Milliseconds@1000 : Integer);
    BEGIN
      //01 EXP - RKA +
      IF NOT ShellIsSend THEN BEGIN
        WSHShell.SendKeys(Text0004);
        ShellIsSend := TRUE;
      END ELSE BEGIN
        IF NOT ShellIsSend2 THEN BEGIN
          WSHShell.SendKeys(Description);
          WSHShell.SendKeys('{DOWN}');
          WSHShell.SendKeys(Filename);
          WSHShell.SendKeys('{DOWN}');
          WSHShell.SendKeys('{Enter}');
          WSHShell.SendKeys('{Enter}');
          ShellIsSend2 := TRUE;
          Timer.Enabled(FALSE);
        END;
      END;
      //01 EXP - RKA -
    END;

    EVENT Timer@1003::TimerError@2(ErrorString@1000 : Text[1024]);
    BEGIN
    END;

    BEGIN
    {
      *---------------------------------------------*
      >   Copyright XXXXXXXXXXXXXXXXXXXXXXXX        >
      >                XXX                          >
      *---------------------------------------------*

      Nr.  Modul Datum     Krzel   Beschreibung
    }
    END.
  }
}


The Form ist tested in Nav. 4.0x. German and English Language.

Regards
Do you make it right, it works too!

Comments

  • arcullarcull Member Posts: 191
    good job garak :)
  • Yaroslav_GaponovYaroslav_Gaponov Member Posts: 158
    Hi


    I must ask a big thanks to Kine for idea with BEEP function
    http://msmvps.com/blogs/kine/archive/2007/09/07/powerfull-command-in-microsoft-dynamics-nav-beep.aspx#comments

    This my tool base on this means - tool for create a NAV release from a lot objects
    http://www.geocities.com/yagaponov/Navision/Release/

    So can be this help you :D
  • kirankumarkirankumar Member Posts: 29
    That's Great work ...

    But I want to know from U how to set the time to take Backup automatically as the code tells.Because, there is no option to set time manually in the form.

    Any help ...?
    Hi
  • garakgarak Member Posts: 3,263
    take a look to the Job Sheduler module in Navision.
    Here you can rznd reports or Codeunits.

    Store this Code into an CU and than run the CU from Sheduler
    Do you make it right, it works too!
  • rajdeepsamantarajdeepsamanta Member Posts: 28
    Great work.. We tried on this through job schedular, but it is not run. Can you tell me the total process of how run job schedular. Please tel me the same.
    Thanks..
  • damodar123damodar123 Member Posts: 36
    hi ,
    Can any one help....................
    i have downloaded one object to take navision backup automatically from the client .But How to set time to take backup at certain intervals.When i set a time interval for the first time its taking backup automatically but next time its not taking backup ,because message coming as Backup complted successfully.
    Due to this reason its generating next backup how to avoid that message.
  • damodar123damodar123 Member Posts: 36
    i have downloaded this ,but how to is this can u tell me.......

    please.................Is it for automatic Backup?
  • SavatageSavatage Member Posts: 7,142
    did you read the post. I think on the first line it say Automatic Backup.

    If you click on the finalization tab you'll see it will ask you to create a scheduled task.
  • mcaverlymcaverly Member Posts: 26
    edited 2010-01-27
    (updated 1/27/2010)=======

    SQL backup works perfectly well for my case, since we are running Navision with MS-SQL database. The entire database is backed up once daily, and all transactions are being backed up very 2 hours. All of these jobs are managed and handled beautifully by SQL server.


    ============= end update 1/27/2010 ======================
    Thanks for your code. It works.

    However, if I set them timeinterval value to 1 hour (3600000), the sendkey commands fail to set the values of those textboxes (description and filename) in the backup-database window. I am trying to test to see whether we could have a Navision session running 24/7 with timer set to be triggered every 1 hour. We want to have the dabase backed up only 1 per day, on certain time in the evening; such as, 10:00PM.

    The timer is unable to sendkey to the backup windows.

    Any advice or suggestion(s)?

    Thanks.
  • garakgarak Member Posts: 3,263
    Between the sendkey commands, you can wait some miliseconds. For example with the BEEP Function
    Do you make it right, it works too!
  • mcaverlymcaverly Member Posts: 26
    I am calling Beep(1,1000);
    It does not work.

    I will try few more times.

    Thanks all for your response.
  • mcaverlymcaverly Member Posts: 26
    I have tried with various durant values, Beep(1,x). However the routine fails to sendkeys to the backup window.

    If I set the timer's interval back to 10, the routine works perfectly.

    Any advice or suggestions?

    Thanks.
  • SavatageSavatage Member Posts: 7,142
  • garakgarak Member Posts: 3,263
    go to Download section (or follow Savatage's link) and try to use
    "DW NavBackup - Navision Backup Tool" It's an external application which run the fin.exe and do the same (Sending keystrokes) like the example in this post.

    The tool in this post here, you can for example use with the job Sheduler ...

    Regards
    Do you make it right, it works too!
  • DeepDeep Member Posts: 569
    Hi all.

    Can anyone help me know whether it is possible to take a NAV backup (.fbk) with system startup, not NAV startup???
    Regards,

    Deep
    India
  • mkpjsrmkpjsr Member Posts: 587
    garak wrote:
    If you need to create an backup (*.fbk) from the Navision client automaticly, for example at 10:00pm you can use following form / the functions in this form.
    Note, that this is an example for working with WSH.
    OBJECT Form 59003 Checklist Make Navision Backup
    {
      OBJECT-PROPERTIES
      {
        Date=12.10.07;
        Time=16:46:29;
        Modified=Yes;
        Version List=EXP-GesNeuAnalge;
      }
      PROPERTIES
      {
        Width=10890;
        Height=3410;
        CaptionML=[DEU=Checkliste Datensicherungserstellung;
                   ENU=Checklist Make Navision Backup];
        OnOpenForm=BEGIN
                     //01 EXP - RKA +
                     Description := STRSUBSTNO(Text0002,COMPANYNAME,TODAY);
                     CurrForm.txtFilename.ACTIVATE();
                     //01 EXP - RKA -
                   END;
    
      }
      CONTROLS
      {
        { 1   ;CommandButton;6050 ;2640 ;2200 ;550  ;HorzGlue=Right;
                                                     VertGlue=Bottom;
                                                     CaptionML=[DEU=&Erstellen;
                                                                ENU=Create Backup];
                                                     OnPush=VAR
                                                              i@1001 : Integer;
                                                            BEGIN
                                                              //01 EXP - RKA +
                                                              IF (Description = '') THEN
                                                                Description := STRSUBSTNO(Text0002,COMPANYNAME,TODAY);
    
                                                              IF (Filename = '') OR (Filename = STRSUBSTNO(Text0002,COMPANYNAME,TODAY)) THEN
                                                                ERROR(Text0003);
    
                                                              IF ISCLEAR(WSHShell) THEN
                                                                CREATE(WSHShell);
    
                                                              IF ISCLEAR(Timer) THEN
                                                                CREATE(Timer);
    
                                                              Timer.Interval(10);
                                                              Timer.Enabled(TRUE);
                                                              //01 EXP - RKA -
                                                            END;
                                                             }
        { 3   ;Frame        ;220  ;880  ;10450;1540 ;HorzGlue=Both;
                                                     VertGlue=Both;
                                                     ShowCaption=No }
        { 4   ;TextBox      ;3850 ;1100 ;6600 ;440  ;HorzGlue=Both;
                                                     ParentControl=3;
                                                     InFrame=Yes;
                                                     CaptionML=[DEU=Beschreibung;
                                                                ENU=Description];
                                                     SourceExpr=Description }
        { 5   ;Label        ;440  ;1100 ;3300 ;440  ;ParentControl=4 }
        { 6   ;TextBox      ;3850 ;1760 ;6600 ;440  ;Name=txtFilename;
                                                     HorzGlue=Both;
                                                     ParentControl=3;
                                                     InFrame=Yes;
                                                     CaptionML=[DEU=Dateiname;
                                                                ENU=Filename];
                                                     SourceExpr=Filename;
                                                     OnAssistEdit=BEGIN
                                                                    //01 EXP - RKA +
                                                                    Filename := CMDMgmt.OpenFile(Text0001,STRSUBSTNO(Text0002,COMPANYNAME,TODAY) + '.fbk',4,'*.fbk',1);
                                                                    IF (STRPOS(Filename,':\') = 0) THEN
                                                                      Filename := '';
                                                                    //01 EXP - RKA -
                                                                  END;
                                                                   }
        { 7   ;Label        ;440  ;1760 ;3300 ;440  ;ParentControl=6 }
        { 2   ;CommandButton;8470 ;2640 ;2200 ;550  ;HorzGlue=Right;
                                                     VertGlue=Bottom;
                                                     PushAction=FormHelp;
                                                     CaptionML=DEU=&Hilfe }
        { 8   ;Label        ;220  ;0    ;10450;770  ;HorzGlue=Both;
                                                     VertGlue=Top;
                                                     HorzAlign=Center;
                                                     ForeColor=3368703;
                                                     FontSize=15;
                                                     FontBold=Yes;
                                                     LeaderDots=No;
                                                     CaptionML=[DEU=GARAK - Navision Datensicherung;
                                                                ENU=GARAK - Navision Backup] }
      }
      CODE
      {
        VAR
          CMDMgmt@1001 : Codeunit 412;
          WSHShell@1000 : Automation "{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} 1.0:{72C24DD5-D70A-438B-8A42-98424B88AFB8}:'Windows Script Host Object Model'.WshShell";
          Timer@1003 : Automation "{3B311C81-140E-11D5-8B18-00D0590B4EC5} 1.0:{3B311C92-140E-11D5-8B18-00D0590B4EC5}:'Navision Timer 1.0'.Timer" WITHEVENTS;
          ShellIsSend@1005 : Boolean;
          ShellIsSend2@1006 : Boolean;
          Description@1007 : Text[50];
          Filename@1008 : Text[1024];
          Text0001@1002 : TextConst 'DEU=Backup speichern;ENU=Backup save.';
          Text0002@1009 : TextConst 'DEU=Backup %1 vom %2;ENU=Backup %1 by %2';
          Text0003@1010 : TextConst 'DEU=Dateiname ist anzugeben;ENU=Fill out filename';
          Text0004@1000000000 : TextConst 'DEU=%xs;ENU=%tb';
    
        EVENT Timer@1003::Timer@1(Milliseconds@1000 : Integer);
        BEGIN
          //01 EXP - RKA +
          IF NOT ShellIsSend THEN BEGIN
            WSHShell.SendKeys(Text0004);
            ShellIsSend := TRUE;
          END ELSE BEGIN
            IF NOT ShellIsSend2 THEN BEGIN
              WSHShell.SendKeys(Description);
              WSHShell.SendKeys('{DOWN}');
              WSHShell.SendKeys(Filename);
              WSHShell.SendKeys('{DOWN}');
              WSHShell.SendKeys('{Enter}');
              WSHShell.SendKeys('{Enter}');
              ShellIsSend2 := TRUE;
              Timer.Enabled(FALSE);
            END;
          END;
          //01 EXP - RKA -
        END;
    
        EVENT Timer@1003::TimerError@2(ErrorString@1000 : Text[1024]);
        BEGIN
        END;
    
        BEGIN
        {
          *---------------------------------------------*
          >   Copyright XXXXXXXXXXXXXXXXXXXXXXXX        >
          >                XXX                          >
          *---------------------------------------------*
    
          Nr.  Modul Datum     Krzel   Beschreibung
        }
        END.
      }
    }
    
    

    The Form ist tested in Nav. 4.0x. German and English Language.
    if i am trying to compile this form, its giving an error

    A variable was expected, for example
    MyVar
    Customer.Name
  • bstnalmbstnalm Member Posts: 25
    I tried to implement(in NAV09SP1) Garak's autobackup-form into a codeunit and it can be run manually. Next, I put the Job Queue Entry table at the codeunit properties and tried to run it through NAS using Job Queue, but this time it cannot work though there is no error found in the Job Queue Log Entries(all the status are Success).

    May I know whether I missed something?

    Thanks.
  • deepikadeepika Member Posts: 1
    Dear all,

    I have imported the same object, but when i am trying to run the form its throwing an error 'file out of filename'.

    i have debugged the code and later on i found that the error is coming from codeunit common dialog managment when the ocx control is trying to create a backup file.


    i am trying this on NAV 2009, please help me what can i do???
    its quite urgent.

    Regards,
    Deepika
  • SavatageSavatage Member Posts: 7,142
    Please don't post that it's urgent.

    This post is from many years ago and since you're on version 2009 why just not use the SQl backup?
  • krikikriki Member, Moderator Posts: 9,112
    If you are on SQL, use SQL backups. They are a lot faster.
    If you are on native, migrate to SQL Server so you can do SQL Backups. :wink:

    Just a guess: I think your backup is larger than 2GB (old FAT-limit of NAV), so it needs to create a second backup file.
    With some older versions, you need to let the name end in a number (e.g. c:\backup\native_backup_01.fbk), otherwise it gives an error.
    With NAV2009R2 (I don't remember for 2009SP1) this is not needed.

    If you want urgent support, then buy a support ticket with Microsoft.
    Putting urgent in your message is not the right way to get a response in this forum.

    Please see Forum Rule(s) #3.2: Forum Rules.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.