天天看點

Shell腳本_備份/etc資料

vim backup_etc.sh

chmod 755  backup_etc.sh

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

#!/bin/bash

# 備份/etc檔案

# Author:James 2016-10-14

# 同步亞洲時間

ntpdate asia.pool.ntp.org &>

/dev/null

# 以年月日格式顯示日期

date

=$(

date

+%y%m%d)

# 檢視/etc檔案大小

size=$(

du

-sh

/etc

)

# /tmp/etcback檔案夾是否存在

if

[ -d

/tmp/etcback

]

then

echo

"Date:$date!"

>

/tmp/etcback/info

.txt

echo

"Data Size:$size"

>>

/tmp/etcback/info

.txt

cd

/tmp/etcback

# 壓縮/etc和info.txt

tar

-zcf etc-$

date

.

tar

.gz

/etc

info.txt &>

/dev/null

rm

-rf

/tmp/etcback/info

.txt

else

mkdir

/tmp/etcback

echo

"Data Size:$size"

>>

/tmp/etcback/info

.txt

cd

/tmp/etcback

# 壓縮/etc和info.txt

tar

-zcf etc-$

date

.

tar

.gz

/etc

info.txt &>

/dev/null

rm

-rf

/tmp/etcback/info

.txt

fi

來自為知筆記(Wiz)