0

I want backup my mysql database with lvm. I will do the backup with cronjob. Here the pseudocode

  1. Open mysql session
  2. Run SQL FLUSH TABLES WITH READ LOCK
  3. Do backup lvcreate -l100%FREE -s -n mysql-backup /dev/vg00/lv_var
  4. Run SQL UNLOCK TABLES
  5. done

Between step 2 until 4, mysql session must keep opened.

So now I have solved this in my script:

mysql -u root -prootpwd -e "FLUSH TABLES WITH READ LOCK";
lvcreate -l100%FREE -s -n mysql-backup /dev/vg00/lv_var
mysql -u root -prootpwd -e "UNLOCK TABLES";

but how to keep the mysql session open in my script?

Normally, I should open mysql session to run FLUSH TABLES WITH READ LOCK but not terminating the this mysql session. In another shell I should do the lvcreate command, after that I must unlock the tables in the first shell.

The other part with second mysql instance and mysqldump working without problems.

How I can do that?

3
  • 1
    don't reinvent a wheel. Use mylvmbackup. This problem was solved 10 years ago
    – akuzminsky
    Dec 17, 2014 at 17:26
  • hello, mylvmbackup backup backups the whole (in my case) /var (including /var/www) directory. so i only need a mysql-backup... or can i setup lvmbackup to backup ONLY the /var/lib/mysql folder? thanks
    – user260137
    Dec 18, 2014 at 9:19
  • I usually allocate a partition for MySQL only. This is right thing to do in general and make mylvmbackup happy too.
    – akuzminsky
    Dec 18, 2014 at 14:46

0

You must log in to answer this question.

Browse other questions tagged .