🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 备份文件保留5天 ``` #!/bin/sh echo -e "\033[36m""《xxxx重要文件备份》""\033[0m\n\n" BACKUP_DIR=/data/xxx_backup/ NAS_PASSWD="admin123456" export FILE_PRE_STRING="文件前缀" TIME=`date +%Y%m%d%H%M%S` tar -czvf ${BACKUP_DIR}${FILE_PRE_STRING}_${TIME}.tar.gz /opt/文件路径/ echo -e "\033[36m""删除5天前的备份数据 ......""\033[0m\n\n" find ${BACKUP_DIR} -mtime +5 -name "${FILE_PRE_STRING}_*" | xargs rm -f BACKUP_FILES_STRING=`ls ${BACKUP_DIR}/*.tar.gz` BACKUP_FILES=(${BACKUP_FILES_STRING// / }) for file in ${BACKUP_FILES[@]} do echo -e "\033[36m""远程备份文件 $file ......""\033[0m\n\n" >> /data/script/backup.log sshpass -p ${heyu_NAS_PASSWD} rsync -e 'ssh -p 622' ${file} 用户名@192.168.227.123:/volume1/xxxxbackup/filebak/ --progress echo -e "\033[36m""远程备份文件 $file 完成, rename file""\033[0m\n\n" echo -e $(date +%Y-%m-%d\ %H:%M:%S) "\033[36m""haha-flow备份完成...""\033[0m" >> /data/script/backup.log mv ${file} ${file}.transfer done ``` ``` find ${BACKUP_DIR} -mtime +5 -name "${FILE_PRE_STRING}_*" | xargs rm -f ``` 保留5天