This is a backup script
#! /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"
When sh is directly used for execution, a file with data can be generated, but through a timed task* * * * * /bin/sh /home/ubuntu/mysql_dump/mysql_dumps.sh
, the backup file can be generated, the file content is empty, what is the situation?
#! /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 in docker-compose
/usr/local
Mount to the host