国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

Linux centos下設置定時備份任務的方法步驟

2024-08-28 00:02:27
字體:
來源:轉載
供稿:網友

實現準備

# 需要備份文件路徑:/opt/apollo/logs/access_log[root@localhost opt]# cd apollo/[root@localhost apollo]# tree.├── logs│  └── access_log└── test.sh# 文件備份存放路徑:/tmp/logs# 備份文件加上時間戳date + %Y%m%d%H%M%S

1.編寫shell腳本

[root@localhost tmp]# vi /opt/apollo/test.sh# 編譯器# !/bin/bash# 日志備份到該目錄下,定義變量使用單引號mypath='/tmp/logs'# 回應/tmp/logsecho ${mypath}# 要備份的日志mylog='/opt/apollo/logs/access_log'# 回應/opt/apollo/logs/access_logecho ${mylog}# 時間戳,執行命令使用``,esc下面的time=`date +%Y%m%d%H%M%S`# 回應時間戳echo ${time}# 備份日志access_log到/tmp/logs路徑下cp ${mylog} ${mypath}/${time}_access.log# 回應echo ${mypath} ${mypath}/${time}_access.log

2.執行test.sh

[root@localhost apollo]# ./test.sh-bash: ./test.sh: Permission denied

3.執行ls -la

[root@localhost apollo]# ls -latotal 8drwxr-xr-x  2 root root  21 Jan 20 08:00 .drwxr-xr-x. 14 root root 4096 Jan 20 07:07 ..-rw-r--r--  1 root root 489 Jan 20 08:00 test.sh

4.給文件test.sh賦與執行權限

[root@localhost apollo]# chmod +x ./test.sh[root@localhost apollo]# ls -latotal 8drwxr-xr-x  2 root root  21 Jan 20 08:00 .drwxr-xr-x. 14 root root 4096 Jan 20 07:07 ..-rwxr-xr-x  1 root root 489 Jan 20 08:00 test.sh

5.再次執行,腳本沒有報錯

[root@localhost apollo]# ./test.sh/tmp/logs/opt/apollo/logs/access_log20190120080932/tmp/logs /tmp/logs/20190120080932_access.log

6.編輯定時任務

[root@localhost logs]# crontab -eno crontab for root - using an empty onecrontab: installing new crontab

7.查看定時任務

# 每分鐘執行一次test.sh* * * * * sh /opt/apollo/test.sh

8.重啟crond

[root@localhost logs]# service crond reloadRedirecting to /bin/systemctl reload crond.serviceYou have new mail in /var/spool/mail/root

9.編寫文件access_log

# 需要備份文件路徑:/opt/apollo/logs/access_log# 編輯文件[root@localhost logs]# vi /opt/apollo/logs/access_log# 追加內容如下:mmmmmmmmmmmmmmmmmmmmm

10.過1分鐘,再去查備份存放目錄

[root@localhost logs]# cat 20190120083101_access.logdjddjsjsjsjjsjsjsjmmmmmmmmmmmmmmmmmmmmm

11.到此為止,定時備份任務完成.

恭喜你,學會備份了!

12.刪除定時任務

[root@localhost logs]# crontab -rYou have new mail in /var/spool/mail/root

13.查看定時任務

[root@localhost logs]# crontab -lno crontab for root

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網之家。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 温宿县| 临西县| 杭锦后旗| 宜阳县| 临猗县| 荥阳市| 南乐县| 德昌县| 玉屏| 溆浦县| 磐石市| 武宣县| 盖州市| 和田县| 印江| 沁水县| 于都县| 铜山县| 左云县| 都江堰市| 五台县| 彩票| 观塘区| 夏河县| 玛曲县| 阿拉善盟| 潮州市| 鄯善县| 泸州市| 石泉县| 永川市| 安平县| 灵璧县| 桂平市| 巍山| 泰州市| 丰顺县| 西乌| 宾阳县| 噶尔县| 广水市|