A small script that makes logical backups with mysqldump
For small data volume backup, whole library, by date, by library, by table, classification
# date-s "2015/01/01" && bash mybackup.sh
#! /bin/bash# using mysqldump for logical backup # directory structure/backup/date # Delete old backup directory every 7 days db_backup_root= "/backup" today= ' date +%y%m%d ' Old_backup_ Dir= ' date-d '-7 Day "+%y%m%d ' db_user=" root "db_passwd=" Geekoo "sock= ' mysql-u$db_user-p$db_passwd-e" show variables Like '%sock% ' | Grep-v Variable_name | awk {' Print $ '} ' mysql_client= ' which MySQL ' mysqldump_client= ' which mysqldump ' xmysql= ' $mysql _client-s $sock-u$db_ USER-P$DB_PASSWD "xmysqldump=" $mysqldump _client-s $sock-u$db_user-p$db_passwd "If [-D $old _backup_dir]; Thenecho "Delete old backup $old _backup_dir" RM-RF $old _backup_dirfiif [!-D $today]; Thenmkdir-p $db _backup_root/$todayfi $xmysql-e "show databases;" | Grep-ve "(Database|_schema)" > $db _backup_root/$today/db_listwhile read Dbnamedo echo $dbnameif [!-D $db _backup_root /$today/$dbname]; Thenmkdir-p $db _backup_root/$today/$dbnamefi $xmysql-e "use $dbname; Show tables; "| Grep-v tables_in > $db _backup_root/$today/$dbname/table_listwhile read Tablenamedoecho $tablename $xmysqldump $ dbname$tablename-R--events--triggers > $db _backup_root/$today/$dbname/$tablename. Sqldone < $db _backup_root/$today/ $dbname/table_listdone < $db _backup_root/$today/db_list
MySQL logical backup mysqldump