Tips for your database (mysql) script :
1) First list the name all databases in any text file.
Databases are listed as a directory in /var/lib/mysql, if you will execute
Code:
ls -l /var/lib/mysql | grep "^d"
It will give you all directories name of /var/lib/mysql, in short it is detail list of all databases of your mysql
Now cut last column, that is list of databases and save list in a text file using redirection (>) operator
2) Now calculate the lines of text file, it is exact same number of your databases.
store number of lines in a variable.
3) Start your loop
i=1
while value of i is equal to or less than above variable
do
first line of text file (tail -n +$i text_file | head -n 1) - store this in second variable
copy database into backup dir (mysqldump -h host-name -u user-name -pPassword "second-variable" > "backup/firstdatabase.sql")
i=`expr $i + 1`
done
4) use date with firstdatabse.sql so it will store sql file with date & time.
5) Remove the text file
The script will take backup of your all databases as a .sql file.
Every database is saved as a .sql file (separate back ups of each database)
if any database is added, it will take back up of the new database too, you do not need to take back up of new database manually.
This is just an idea, you don't need to follow exactly same as above. you can make your script better and robust. This is the best part of shell scripting.