本文共 888 字,大约阅读时间需要 2 分钟。
#!/bin/bash
sourcepath='/mnt/mongodb/bin'targetpath='/mnt/mongodb/back' #备份目录nowtime=$(date +%Y%m%d)start()
{ ${sourcepath}/mongodump --host 127.0.0.1 --port 20011 -uadmin -p'密码' --authenticationDatabase admin --out ${targetpath}/${nowtime}}execute(){ startif [ $? -eq 0 ]thenecho "back successfully!"elseecho "back failure!"fi}if [ ! -d "${targetpath}/${nowtime}/" ]
thenmkdir ${targetpath}/${nowtime}fiexecuteecho "============== back end ${nowtime} =============="if [ -d "${targetpath}/${nowtime}/" ]
thencd /mnt/mongodb/backtar -cvzf ${targetpath}/${nowtime}.tar.gz ${nowtime}fiexecuteecho "============== back end ${nowtime} =============="if [ -d "${targetpath}/${nowtime}/" ]
thenrm -rf /mnt/mongodb/back/"${nowtime}"fifind /mnt/mongodb/back/ -type f -name "*.tar.gz" -mtime +6| xargs rm -fr {}; #只保留6天的备份文件。转载于:https://blog.51cto.com/woniu123/2108552