怎么在Linux中设置定时备份任务
发表于:2024-10-20 作者:千家信息网编辑
千家信息网最后更新 2024年10月20日,这期内容当中小编将会给大家带来有关怎么在Linux中设置定时备份任务,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。实现准备# 需要备份文件路径:/opt/apoll
千家信息网最后更新 2024年10月20日怎么在Linux中设置定时备份任务
这期内容当中小编将会给大家带来有关怎么在Linux中设置定时备份任务,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
实现准备
# 需要备份文件路径:/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
什么是Linux系统
Linux是一种免费使用和自由传播的类UNIX操作系统,是一个基于POSIX的多用户、多任务、支持多线程和多CPU的操作系统,使用Linux能运行主要的Unix工具软件、应用程序和网络协议。
上述就是小编为大家分享的怎么在Linux中设置定时备份任务了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注行业资讯频道。
备份
任务
文件
路径
内容
日志
时间
系统
中设
操作系统
目录
脚本
分析
自由
到此为止
专业
中小
内容丰富
再次
变量
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
国际标准的数据库设计说明书框架
jdbc连接数据库封装
杭州九旺网络技术有限公司6
河北app软件开发按需定制
数据库属于文件管理吗
盐城企业网络安全准入控制供应商
警察网络安全和执法
广州学困网络技术
惠普服务器远程管理卡
开源软件开发实战
拍照识字软件开发
常用的企业网络安全技术
长沙网络棋牌软件开发公司
网络安全攻防初级
别人转发给我的彩票数据库
湖北系统软件开发靠谱吗
网络安全人才签约
学生干部网络安全教育
两个网站可以用一个数据库
重庆国瑞网络技术
网络安全为什么那么难
开拓者济南网络技术
网络技术就业分析报告
建一个数据库用到的语言顺序
拍照识字软件开发
poco软件开发
判断数据库表格有没有更新
北京电商软件开发要多少钱
智联网公司网络安全人才市场
联通服务器地址和端口是什么