用于备份用户数据库的Shell脚本

[英]Shell script to backup databases of users


I have the shell script which first goes in home directory and backups all folders like

我有shell脚本,它首先进入主目录并备份所有文件夹,如

OCT-13-2010/username/homebck.tar.gz

and i also backups the database ,ef if i am in user1 folder then all my databases are like username_web

我也备份数据库,如果我在user1文件夹中,那么我的所有数据库都像username_web

and i use the following to backup

我使用以下备份

mysqldump --skip-lock-tables -u sqluser -ppassword --skip-extended-insert ${FOLDERNAME}_web | gzip > /backups/mysql/${date2}/DBF_${date1}_${FOLDERNAME}.sql.gz" - ${FOLDERNAME}

This is working fine but the problem is here the name of database has to be username_web

这工作正常,但问题是这里数据库的名称必须是username_web

because when i am in the script then there is no way for me to find the databases of user1 and then backup those.

因为当我在脚本中时,我无法找到user1的数据库,然后备份这些数据库。

Is there any way because i want to put separate databases in separate folders

有什么办法,因为我想将单独的数据库放在单独的文件夹中

1 个解决方案

#1


0  

how do you define 'the databases of user1'?

你如何定义'user1的数据库'?

if it's all databases named after the user, you could do something like:

如果它是以用户命名的所有数据库,您可以执行以下操作:

for db in $(mysql -h 127.0.0.1 -e "select schema_name from information_schema.schemata where schema_name like '$username\\_%';"); do
  mysqldump $db ........
done
智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2010/10/13/fe79a55a69850d682e15144613c2d0c3.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告