您的位置 首页 企业运维

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

 

欢迎来撩 : 汇总all

白眉大叔

关于白眉大叔linux云计算: 白眉大叔

热门文章