51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

linux 定时备份文件并删除

linux 定时备份文件并删除

需求, 定时备份某个目录,并且删除 7天前的备份文件, 不然文件太大撑爆硬盘

compress_backup.sh

#!/bin/bash
source_folder=/mnt/data/wik/confluce-data

backup_base=/mnt/zzy/data/back/confluce-data/
backup_folder=${backup_base}/`date "+%Y-%m-%d"`



source_folder_name=confluce-data.tar.gz

echo "source_folder:$source_folder"
echo "backup_folder: $backup_folder"
echo "source_folder_name: $source_folder_name"

#新建立文件夹
#mkdir -p ${backup_folder}/`date "+%Y-%m-%d"`
mkdir -p ${backup_folder}


#压缩命令
tar -zcvPf $backup_folder/$source_folder_name  $source_folder
echo "$source_folder_name文件备份成功"

# 移除7天以前的备份文件包

find ${backup_base} -type d -mtime +7 | xargs rm -rf
赞(6)
未经允许不得转载:工具盒子 » linux 定时备份文件并删除