Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set scheduled backup tasks in Linux

2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

In this issue, the editor will bring you about how to set up scheduled backup tasks in Linux. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

Realization preparation

# backup file path: / opt/apollo/logs/access_ log [root @ localhost opt] # cd apollo/ [root@localhost apollo] # tree. ├── logs │ └── access_log └── test.sh# file backup path: / tmp/logs# backup file plus timestamp date +% Y%m%d%H%M%S

1. Write shell scripts

[root@localhost tmp] # vi / opt/apollo/test.sh# compiler #! / bin/bash# logs are backed up to this directory, define variables to use single quotation marks mypath='/tmp/logs'# response / tmp/logsecho ${mypath} # log mylog='/opt/apollo/logs/access_log'# response / opt/apollo/logs/access_logecho ${mylog} # timestamp, execute command using `` Time= `date +% Y% m% d% H% M% S` # response timestamp echo ${time} # backup log access _ log to / tmp/logs path cp ${mylog} ${mypath} / ${time} _ access.log# response echo ${mypath} ${mypath} / ${time} _ access.log

two。 Execute test.sh

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

3. Execute 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. Assign execution permissions to the file 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. Execute again, the script did not report an error

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

6. Edit scheduled tasks

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

7. View scheduled tasks

# execute test.sh* sh / opt/apollo/test.sh every minute

8. Restart crond

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

9. Write a file access_log

# need to backup file path: / opt/apollo/logs/access_log# edit file [root@localhost logs] # vi / opt/apollo/logs/access_log# append as follows: mmmmmmmmmmmmmmmmmmmmm

10. In a minute, check the backup directory.

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

11. So far, the scheduled backup task is completed.

Congratulations, you have learned to back up!

twelve。 Delete scheduled tasks

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

13. View scheduled tasks

[root@localhost logs] # crontab-lno crontab for root what is a Linux system Linux is a free to use and freely spread UNIX-like operating system, is a POSIX-based multi-user, multi-tasking, multi-threading and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.

The above is how to set up scheduled backup tasks in Linux. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report