Linux shell mini script sharing
Our website is going to go to the cloud recently, and we need to migrate the database. Among them, a business that generates website viewing logs generates a table every day, and the amount of data is about 3 million. At present, there are nearly 3 million days of data in the database, that is, 500 tables. The naming rules are as follows: MariaDB [log] > show tables. | | pvlogs_20170615 | | pvlogs_20170616 | | pvlogs_20170617 | | pvlogs_20170619 | | pvlogs_20170620 | | pvlogs_20170621 | | pvlogs_20170622 | | pvlogs_20170623 | now I am asked to dump all these tables first, and one mysqldump at a time. This is absolutely impossible, so I thought of using the shell script to complete it. | The details are as follows: [root@S143 ~] # cat mysqldumplog.sh #! / bin/bash datenum= `date +% Y%m%d-d '498 days ago' `date +% Y% m% d`while [$datenum-lt $nowdate] do mysqldump-uroot-p * log pvlogs_$datenum | gzip > / backup_mysql/mysql_143/log/pvlogs_$datenum.sql Datenum= `date-d "$datenum 1 days" + "% Y%m%d" `done Note: 1:date +% Y%m%d-d '498 days ago' takes out the date 498 days ago, and 2:date-d "$datenum 1 days" + "% Y%m%d" adds one day to the specified date. The script is simple, but it makes sense for people who are new to linux shell.