# 保留10天数据，
# mysqldocker 为安装mysql的docker
docker exec -i mysql bash<<'EOF'
# 判断目录是不是已经存在，如果不存在则创建
if [ ! -d "/backups/mysql" ]; then
  mkdir -p /backups/mysql
fi
# supervision 为数据库的名称
#mysqldump -h localhost -uroot -pPassword01 PhoneQuickTask > /backups/mysql/PhoneQuickTask_$(date +%Y%m%d).sql

mysqldump -h localhost -uroot -pV?skI.2n+yo6220137 --events --routines --triggers VCA > /backups/mysql/VCA_$(date +%Y%m%d).sql

#mysqldump -h localhost -uroot -pPassword01 metabase > /backups/mysql/metabase_$(date +%Y%m%d).sql

#mysqldump -h localhost -uroot -pPassword01 UserManagement > /backups/mysql/UserManagement_$(date +%Y%m%d).sql

#mysqldump -h localhost -uroot -pPassword01 VideoCollection > /backups/mysql/VideoCollection_$(date +%Y%m%d).sql
#删除超过10天的数据
#rm -f /backups/mysql/PhoneQuickTask_$(date -d -10day +%Y%m%d).sql
rm -f /backups/mysql/VCA_$(date -d -3day +%Y%m%d).sql
#rm -f /backups/mysql/metabase_$(date -d -10day +%Y%m%d).sql
#rm -f /backups/mysql/UserManagement_$(date -d -10day +%Y%m%d).sql
#rm -f /backups/mysql/VideoCollection_$(date -d -10day +%Y%m%d).sql
exit
EOF
# 判断目录是不是已经存在，如果不存在则创建
if [ ! -d "/backups/mysql" ]; then
  mkdir -p /backups/mysql
fi
# 将docker中的备份的数据拷贝到宿主机上。
#sudo docker cp mysql:/backups/mysql/PhoneQuickTask_$(date +%Y%m%d).sql /home/backups/mysql
sudo docker cp mysql:/backups/mysql/VCA_$(date +%Y%m%d).sql /home/backups/mysql
#sudo docker cp mysql:/backups/mysql/metabase_$(date +%Y%m%d).sql /home/backups/mysql
#sudo docker cp mysql:/backups/mysql/UserManagement_$(date +%Y%m%d).sql /home/backups/mysql
#sudo docker cp mysql:/backups/mysql/VideoCollection_$(date +%Y%m%d).sql /home/backups/mysql
#删除超过10天的数据
#rm -f /home/backups/mysql/PhoneQuickTask_$(date -d -10day +%Y%m%d).sql
rm -f /home/backups/mysql/VCA_$(date -d -3day +%Y%m%d).sql
#rm -f /home/backups/mysql/metabase_$(date -d -10day +%Y%m%d).sql
#rm -f /home/backups/mysql/UserManagement_$(date -d -10day +%Y%m%d).sql
#rm -f /home/backups/mysql/VideoCollection_$(date -d -10day +%Y%m%d).sql
