Mysqldump all tables from database in separate files

From DevOps Notebook
Revision as of 16:50, 9 October 2020 by MilosZ (talk | contribs) (Created page with "<syntaxhighlight lang="bash"> #!/bin/bash USER=myuser PASSWORD=mypwd DATABASE=nameofdb for i in $(mysql -uUser -pPASSWORD DATABASE -e "show tables;"|grep -v Tables_in_);do my...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

<syntaxhighlight lang="bash">

  1. !/bin/bash

USER=myuser PASSWORD=mypwd DATABASE=nameofdb

for i in $(mysql -uUser -pPASSWORD DATABASE -e "show tables;"|grep -v Tables_in_);do mysqldump -u$USER -p$PASSWORD $DATABASE $i > /destination/dir/$i".sql";done

tar -cjvf "backup_mysql_"$(date +'%Y%m%d')".tar.bz2" /destination/dir/*.sql </syntaxhighligh>