Linux scheduled task backup docker database problem

this is a backup script

-sharp!/bin/bash
docker_name=mysql_container
data_dir=/home/ubuntu/mysql_dump
/usr/bin/docker exec -it $docker_name /usr/bin/mysqldump -u root -p root --all-databases > "$data_dir/data_`date +%Y%m%d`.sql"

A file with data can be generated by using sh directly, but through the scheduled task * / bin/sh / home/ubuntu/mysql_dump/mysql_dumps.sh , the backup file can be generated and the file content is empty. What is the situation?

Mar.02,2021

-sharp!/bin/bash
docker_name=mysql_container
data_dir=/home/ubuntu/.data/mysql_dump
/usr/bin/docker exec $docker_name sh -c "mysqldump -uql -pqliang978 --databases voyager > /var/local/data_`date +%Y%m%d`.sql"
find $data_dir -mtime +7 -name 'data_*.sql' -exec sudo rm {} \

modify the bash script, and then mount / usr/local to the host in docker-compose

Menu