• 备份并删除7天以前数据


    需求:

    有根据年月日时分创建的目录结构中数据需要按照每天进行备份,

    原始目录

    [root@LAB_1 logs]# cd /home/logs/2/2017/12/06/

    备份目录

    [root@LAB_1 bak]# cd /home/logs/bak/

    备份脚本在备份目录中,计划任务中,每天凌晨1点备份并压缩7天之前的数据,并将老的文件目录给删除。

    脚本如下:

    #!/bin/bash
    
    #7 days ago
    
    S_Path=/home/logs/2
    
    D_Path=/home/logs/bak
    
    S_FileName=$(date -d "-7 days" "+%Y/%m/%d")
    
    D_FileName=$(date -d "-7 days" "+%Y%m%d")
    
    cd $S_Path/
    
    tar -zcvf $D_Path/$D_FileName.tar.gz $S_FileName
    
    if [ $? == 0 ];then
    
    echo "back 7 days ago file sucessful!"
    
    rm -rf $S_FileName
    
    echo "delete 7 days ago file sucessful!"
    
    else
    
    echo "back 7 days ago file fail!"
    
    fi
    

      

  • 相关阅读:
    164-268. 丢失的数字
    163-20. 有效的括号
    Sword 30
    Sword 29
    Sword 27
    Sword 25
    Sword 24
    Sword 22
    Sword 21
    Sword 18
  • 原文地址:https://www.cnblogs.com/xzlive/p/9379390.html
Copyright © 2020-2023  润新知