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
|