You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#!/bin/bash
name = "base2024"
# 工程目录
pwd = $( pwd )
data_dir = $pwd "/db/backup/"
docker exec -i db mariadb-dump --databases $name --user= root --password= ${ name } 1415926 > " $data_dir /bak_`date +%Y-%m-%d_%H:%M:%S`.sql "
# 删除14天以前的备份
find $data_dir -mtime +14 -name 'bak_*.sql' -exec rm -rf { } \;
## 备份mongodb
docker exec -i mongodb mongodump -u${ name } -p${ name } 1415926 -d ${ name } --authenticationDatabase admin --archive= /data/backup/` date +%Y-%m-%d_%H:%M:%S` .bak
# 删除14天以前的备份
find ${ pwd } /mongodb/backup/ -mtime +14 -name 'bak_*.sql' -exec rm -rf { } \;
# 创建定时任务
# crontab -e
# 每天凌晨3点半定时备份Docker中的MySQL
# 30 3 * * * sh /data/funds_2024/db-backup.sh > /dev/null 2>&1
#重载一遍crond
# systemctl reload crond.service
#查看任务
# crontab -l
# mongodb恢复:
# mongorestore --host=localhost --port=27017 --username=oa --password=oa1415926 --authenticationDatabase=admin --db=oa --dir=/data/backup/awl_oa/
# mysql恢复
# source file