Mysqldump all tables from database in separate files

From DevOps Notebook
Revision as of 16:51, 9 October 2020 by MilosZ (talk | contribs)
#!/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