The configuration file is as follows
######### #BACKUP MYSQL config####### #database namedb_name=testdb_user=rootdb_pass=123456#### #backup Day Configbegin # # # # #day_backupdir =/home/backup/db/dayday_backup_fix=dayday_interval=1#### #backup Day Configend ############ Backup Week Configbegin # #week_backupdir =/home/backup/db/weekweek_backup_fix=weekweek_interval=2#### #backup Week configend ########### #backup month config begin # # # #month_backupdir =/home/backup/db/monthmonth_backup_fix= monthmonth_interval=3#### #backup Month config end #######
Name is: db_config
The shell script is as follows:
#!/bin/bash# name:bak_ftp_day.sh# this is a shellscript for auto file backup and delete old backup# #DIR变量为当前shell脚本的目录DIR = "$ ( cd " $ ( dirname "${bash_source[0]}" " && pwd )" #使用source命令导入平级目录下的配置文件, Once introduced, the values in the file can be obtained directly from the variable names in the configuration source $DIR "/" Db_configtime=_ ' date +%Y_%m_%d_%H_%M_%S ' _echo "------bakup---<<<--' date +%y-%m-%d-%h-%m-%s '----BEGIN--->>>---";echo $day _ backupdir/$db _name$time$day_backup_fix.sql.gz "---is --begin---";mysqldump -u $db _user -p$ db_pass $db _name | gzip > $day _backupdir/$db _name$time$day_backup_fix.sql.gzecho $day _backupdir/$db _name$time$day_backup_fix.sql.gz "---is --finsh---";find $day _backupdir -name $db _name "*.sql.gz" -type f -mmin + $day _INTERVAL&NBSP;-EXEC&NBSP;RM&NBSP;-RF {} \; > /dev/null 2>&1echo "------bakup----<<<---' date +%y-%m-%d-%h-%m-%s '----finsh--->> >---";echo " ";
How to read a configuration file in the same directory as the shell script in a Linux shell script