docker定时任务Mysql脚本
#!/bin/bash # 定义备份参数 number=31 backup_dir=/root/mysqlbackup dd=`date +%Y-%m-%d` tool=docker exec -i mysql mysqldump username=root password=123456 database_name=dbname # 如果备份目录不存在,则创建 if [ ! -d $backup_dir ]; then mkdir -p $backup_dir; fi # 执行mysqldump命令备份数据库 docker exec -i mysql mysqldump -u$username -p$password. $database_name>$backup_dir/bangong_$dd.sql # 记录备份日志 echo "create $backup_dir/$database_name-$dd.sql" >> $backup_dir/log.txt # 删除超过设定天数的备份文件 count=`ls -l -crt $backup_dir/*.sql | awk '{print $9 }' | wc -l` if [ $count -gt $number ]; then delfile=`ls -l -crt $backup_dir/*.sql | awk '{print $9 }' | head -1` rm $delfile echo "delete $delfile" >> $backup_dir/log.txt fi
============ 欢迎各位老板打赏~ ===========
与本文相关的文章
- · Amazon Linux 2023 安装Docker和Docker Compose
- · 修改Docker的默认网段
- · 解决Linux实例磁盘空间满问题
- · failed to fetch metadata: fork/exec /home/appuser/.docker/cli-plugins/docker-buildx: exec format error
- · Docker登录login报错Error saving credentials
- · docker安装mysql8注意事项
- · .NET8 Mysql SSL error
- · 黑群晖docker无法pull镜像,x509错误解决方法
- · k3s+kuboard快速搭建K8s生产环境集群
- · 解决es报错:blocked by: [FORBIDDEN/12/index read-only / allow delete (api) ]
- · filebeat按docker容器名创建不同的索引
- · traefik负载均衡/滚动升级