Instructions to include a backup script in espoCRM

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shalmaxb
    Senior Member
    • Mar 2015
    • 1603

    Instructions to include a backup script in espoCRM

    Hello,

    the user item provided this script: https://forum.espocrm.com/forum/inst...5274#post75274
    Any help, where to put it and how to use is appreciated.

    Can be found here: https://docs.espocrm.com/administrat...p-and-restore/
    Last edited by shalmaxb; 10-07-2021, 06:39 AM.
  • esforim
    Active Community Member
    • Jan 2020
    • 2204

    #2
    It look like a standard script function, I think I only ever run bash script less than 5 times in my lifetime as there was no other option at that time.

    Using the CLI I believe, you can probably use it. Here is my guess:
    (1) download, edit the file, upload it somewhere, probably same folder as EspoCRM or 1 level above it, as for editing I think you need to edit; filepath, password, username in that fle.
    (2) use a commandline tools. For example CMD for Windows, but I remember Windows don't support Bash 'language' so you must install some 3rd party Bash 'decoder'... but Linux by default I think they support Bash language.

    So my guess is... do you remember how you use your 'CLI' to upgrade your server? Instead of running, "php update" which is basically saying, "Using PHP to run the file call update".

    In this case you would need to invoke the Bash command, something like, "bash backup.sh" and it should run the file using the program/language bash. Finally to verify my theory I did a search online and briefly reading through the guide it seem to be right:


    Either run with "bash filename" or "sh filename"

    Comment


    • esforim
      esforim commented
      Editing a comment
      Reading item script I think he made it even easier, maybe you only need to edit/amended the path.

      He grab the other details for you using these code I think;


      DB_NAME=$(php -r "\$config=include('data/config.php'); echo @\$config['database']['dbname'];")
      DB_USER=$(php -r "\$config=include('data/config.php'); echo @\$config['database']['user'];")
      DB_PASS=$(php -r "\$config=include('data/config.php'); echo @\$config['database']['password'];")

      If you are successful in your venture I might give it a try too... manually updating make me lazy.
  • item
    Active Community Member
    • Mar 2017
    • 1476

    #3
    Hello,

    create a Jobs ..

    PHP Code:
    <?php
    
    namespace Espo\Custom\Jobs;
    
    class BackupJobs extends \Espo\Core\Jobs\Base
    {
    
    public function run()
    {
    $GLOBALS['log']->warning( "Begin BackupJobs");
    $pdo = $this->getEntityManager()->getPDO();
    $sql = "DELETE FROM scheduled_job_log_record WHERE status='Success';DELETE FROM job WHERE status='Success'";
    $sth = $pdo->prepare($sql);
    $sth->execute();
    
    @exec('cd /PATH/backups;bash ./backup.sh > /dev/null &');
    $GLOBALS['log']->warning( "End BackupJobs" );
    }
    }
    + scheduler.json add the entry for the new jobs .. clear cache
    + put this jobs run every week

    change PATH. to something :

    /blabla/blabla/espocrmroot/public

    to /babla/backups. normaly www have access
    change in the script to
    make executable the script : https://www.andrewcbancroft.com/blog...pt-executable/

    it's done

    If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

    Comment

    • shalmaxb
      Senior Member
      • Mar 2015
      • 1603

      #4
      Thank you for your help. I tried to execute the bash file in my local installation (WAMP environment) with Windows Subsystem Linux. But that is very complicated for me, as the command structure is different and I always get errors. Guessing, what could be right, takes hours.

      I guess, with the php-script in the thread above I could avoid trying to execute the bash in Windows. I will try to implement it.

      Comment

      • shalmaxb
        Senior Member
        • Mar 2015
        • 1603

        #5
        Hello, I followed the instructuions and the script seems to work (at least no error), but there is no backup file anywhere.
        I did not understand the second line of the bash:

        DEFAULT_BACKUP_PATH=$(pwd)

        Will I have to put there the path to my created backup folder? What does $(pwd) mean?

        Comment

        • item
          Active Community Member
          • Mar 2017
          • 1476

          #6

          DEFAULT_BACKUP_PATH=$(pwd)

          DEFAULT_BACKUP_PATH='C:\pathToBackupPlace". on windows

          DEFAULT_BACKUP_PATH="/pathToBackupPlace"

          This script of Yuri is interactive...user need to respond.

          i have a little modified for non-interactive :

          if [ ! -d "$BACKUP_PATH" ]; then
          echo "Error: The directory '$BACKUP_PATH' does not exist."
          exit 1
          fi

          if [ ! -w "$BACKUP_PATH" ]; then
          echo "Error: Backup directory '$BACKUP_PATH' is not writable."
          exit 1
          fi

          cd $PATH_TO_ESPO

          if [ ! -f "data/config.php" ]; then
          echo "Error: The '$PATH_TO_ESPO' is not EspoCRM directory."
          exit 1
          fi


          Edit : if not forget : $(pwd) is i think when run from command line

          ./Backup.sh "/pathThoBackup". (it's a variable)

          Last edited by item; 10-07-2021, 05:43 PM.
          If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

          Comment

          Working...