mariadb lock tables from linux bash



  • I have all codes that I need to do a backup (lvm snapshot) for our MariaDB Database on Linux. These are my commands in terminal:

    mysql
    flush tables read lock;                        (in database)
    exit
    lvc create -l100%free -s -n mdbsnap /dev/vgm/lv
    mysql
    unlock tables;                                 (in database)
    exit
    

    And it works.

    But right now I'm trying to automate the processes with Linux bash:

    #!/bin/bash
    mysql -e "flush tables with read lock"
    lvc create -l100%free -s -n mdbsnap /dev/vgm/lv
    mysql -e "unlock tables"
    

    and it doesn't work (the locking doesn't work and the database doensn't stay locked). I think this is because I should keep my mysql connection open to force our database stay locked during snapshot. Does anyone have any idea?



  • With the help of another stackexchange's question I found the answer:

    #!/bin/bash
    echo
    {
    echo "
    flush tables with read lock;
    system lvccreate -l100%free -s -n mdbsnap /dev/vgm/lv;
    "
    }  | mysql --unbuffered 
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2