欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

shell實(shí)現(xiàn)目錄增量備份的示例代碼

 更新時(shí)間:2024年08月28日 10:37:28   作者:小黑要上天  
本文主要介紹了shell實(shí)現(xiàn)目錄增量備份的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

auto_backup_system.sh 

#針對(duì)目錄進(jìn)行備份;每周1-6執(zhí)行增量備份,每周日(值為:0 or 7)執(zhí)行全備份

#!/bin/bash
#Automatic Backup Linux System Files
#By Author xiaoheiyaoshangtian
#2024/x/x

source_dir=($*)
target_dir=/tmp
year=$(date +%Y)
month=$(date +%m)
day=$(date +%d)
week=$(date +%u)
files=system_backup.tar.gz
code=$?

if [ -z $source_dir ];then
  echo -e "Please Enter File or Directory You Need to Backup:\n--------------------------------------------------\nExample    $0 /boot /etc ......"
  exit
fi

#determin whether the target directory exists
if [ ! -d $target_dir/$year/$month/$day ];then
  mkdir -p $target_dir/$year/$month/$day
  echo "This $target_dir/$year/$month/$day created successfully!"
fi

#exec full backup function command
full_backup()
{
  if [ "$week" -eq "0" ];then
    rm -rf $target_dir/snapshot
    cd $target_dir/$year/$month/$day
    tar -g $target_dir/snapshot -czvPf $files $(echo ${source_dir[@]})
    [ "$code" == "0" ]&&echo -e "---------------------------------------\nfull_backup system files backup successfully!"
  fi
}

#perform incremental backup function command
add_backup()
{
  cd $target_dir/$year/$month/$day
  if [ -f $target_dir/$year/$month/$day/$files ];then
    read -p "$files already exists,overwrite confirmation yes or no(default yes)?:" sure
    if [ "$sure" == "no" -o "$sure" == "n" -o "$sure" == "N" -o "$sure" == "NO" -o "$sure" ==  "No" ];then
      sleep 1
      exit 0
    fi
    if [ $week -ne "0" ];then
    cd $target_dir/$year/$month/$day
    tar -g $target_dir/snapshot -czvPf $$_$files $(echo ${source_dir[@]})
    [ "$code" == "0" ]&&echo -e "---------------------------------------\nadd_backup system files backup successfully!"
    fi
  else
    if [ $week -ne "0" ];then
    cd $target_dir/$year/$month/$day
    tar -g $target_dir/snapshot -czvPf $files $(echo ${source_dir[@]})
    [ "$code" == "0" ]&&echo -e "---------------------------------------\nadd_backup system files backup successfully!"
    fi
  fi 
}

full_backup
add_backup

驗(yàn)證:

[root@logstash ~]# sh auto_backup_system.sh
Please Enter File or Directory You Need to Backup:
--------------------------------------------------
Example    auto_backup_system.sh /boot /etc ......
[root@logstash ~]# 
[root@logstash ~]# sh auto_backup_system.sh /tmp
This /tmp/2024/06/21 created successfully!
tar: /tmp: Directory is new
tar: /tmp/.ICE-unix: Directory is new
tar: /tmp/.Test-unix: Directory is new
tar: /tmp/.X11-unix: Directory is new
tar: /tmp/.XIM-unix: Directory is new
tar: /tmp/.font-unix: Directory is new
tar: /tmp/2024: Directory is new
tar: /tmp/2024/06: Directory is new
tar: /tmp/2024/06/21: Directory is new
/tmp/
/tmp/.ICE-unix/
/tmp/.Test-unix/
/tmp/.X11-unix/
/tmp/.XIM-unix/
/tmp/.font-unix/
/tmp/2024/
/tmp/2024/06/
/tmp/2024/06/21/
/tmp/snapshot
/tmp/2024/06/21/system_backup.tar.gz
---------------------------------------
add_backup system files backup successfully!
[root@logstash ~]# 
[root@logstash ~]# sh auto_backup_system.sh /tmp
system_backup.tar.gz already exists,overwrite confirmation yes or no(default yes)?:no
[root@logstash ~]# 
[root@logstash ~]# sh auto_backup_system.sh /tmp
system_backup.tar.gz already exists,overwrite confirmation yes or no(default yes)?:
/tmp/
/tmp/.ICE-unix/
/tmp/.Test-unix/
/tmp/.X11-unix/
/tmp/.XIM-unix/
/tmp/.font-unix/
/tmp/2024/
/tmp/2024/06/
/tmp/2024/06/21/
/tmp/2024/06/21/2577_system_backup.tar.gz
---------------------------------------
add_backup system files backup successfully!
[root@logstash ~]# 
[root@logstash tmp]# ls
2024  snapshot
[root@logstash tmp]# 
[root@logstash tmp]# cd 2024/
[root@logstash 2024]# cd 06/21/
[root@logstash 21]# ls
2577_system_backup.tar.gz  system_backup.tar.gz
[root@logstash 21]# 

到此這篇關(guān)于shell實(shí)現(xiàn)目錄增量備份的示例代碼的文章就介紹到這了,更多相關(guān)shell 目錄增量備份內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家! 

相關(guān)文章

  • shell命令while循環(huán)中使用sleep命令代碼示例

    shell命令while循環(huán)中使用sleep命令代碼示例

    這篇文章主要介紹了shell命令while循環(huán)中使用sleep命令代碼示例,分享了相關(guān)代碼示例,小編覺得還是挺不錯(cuò)的,具有一定借鑒價(jià)值,需要的朋友可以參考下
    2018-02-02
  • Linux Bash腳本中的IFS的作用

    Linux Bash腳本中的IFS的作用

    ??在處理文本數(shù)據(jù)時(shí),Bash 將文本分割成多個(gè)字段,這些字段之間由 IFS 指定的字符進(jìn)行分隔,本文主要介紹了Linux Bash腳本中的IFS的作用,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-05-05
  • Linux下的fdisk指令用法場景分析

    Linux下的fdisk指令用法場景分析

    在Linux系統(tǒng)中,對(duì)磁盤進(jìn)行分區(qū)是管理和利用磁盤空間的重要任務(wù)之一,本篇將以通俗易懂的方式,詳細(xì)介紹fdisk指令的前世今生、功能、用法和應(yīng)用場景,幫助讀者全面了解fdisk指令,并掌握其在磁盤管理和問題排查方面的應(yīng)用,需要的朋友可以參考下
    2024-01-01
  • ps命令輸出進(jìn)程狀態(tài)S+的含義解析

    ps命令輸出進(jìn)程狀態(tài)S+的含義解析

    這篇文章主要介紹了ps命令輸出進(jìn)程狀態(tài)S后面加號(hào)的含義,本文通過ps命令輸出說明,感興趣的朋友跟隨小編一起看看吧
    2019-12-12
  • shell命令之mv的具體使用

    shell命令之mv的具體使用

    本文主要介紹了shell命令之mv的具體使用,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • Linux下的tar壓縮解壓縮命令詳解(小結(jié))

    Linux下的tar壓縮解壓縮命令詳解(小結(jié))

    這篇文章給大家分享了linux下的tar 壓縮解壓縮命令,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下
    2017-03-03
  • linux反彈shell的原理詳解

    linux反彈shell的原理詳解

    這篇文章主要介紹了linux反彈shell的原理詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-10-10
  • 基于shell的if和else詳解

    基于shell的if和else詳解

    下面小編就為大家?guī)硪黄趕hell的if和else詳解。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-06-06
  • 修改Apache配置指定php配置文件php.ini的位置方法

    修改Apache配置指定php配置文件php.ini的位置方法

    下面小編就為大家?guī)硪黄薷腁pache配置指定php配置文件php.ini的位置方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-02-02
  • shell腳本去重的三種方法小結(jié)

    shell腳本去重的三種方法小結(jié)

    在實(shí)際工作中,進(jìn)行Shell去重操作是非常常見的任務(wù)之一,本文主要介紹了shell腳本去重的三種方法小結(jié),具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-12-12

最新評(píng)論