Reputation: 853
I have a script to dump my databases, like this :
#!/usr/bin/env sh
PATH=/usr/bin:/bin
LOG="mybackup/log/backup_$(date +%Y-%m-%d_%H:%M:%S).log"
# some other command
# backup mysql database
echo "Backing up database" > ~/$LOG
mysqldump -u myusername -pmypassword --ignore-table={db1.table1,db1.table2,db1.table3,db1.table4} db1 -r ~/mybackup/db/db1_$(date +%Y-%m-%d_%H:%M:%S).sql >> ~/$LOG 2>&1
# some other command
When I run the command in terminal, it successfully dump my database without ignored tables. But when I run the command through the script, it dump all tables in the database.
I have tried to escape the curly braces :
mysqldump -u myusername -pmypassword --ignore-table=\{db1.table1,db1.table2,db1.table3,db1.table4\} db1 -r ~/mybackup/db/db1_$(date +%Y-%m-%d_%H:%M:%S).sql
but it still dump all table.
My question is how to escape braces/brackets properly in shell script?
Upvotes: 0
Views: 536
Reputation: 1833
I can't answer why it DOES work on command line, but the documentation says to use the option multiple times:
mysqldump --ignore-table documentation
man mylsqdump
--ignore-table=db_name.tbl_name
Do not dump the given table, which must be specified using both the database and table names. To ignore multiple tables, use this option multiple times. This option also can be used to ignore views.
Upvotes: 1