Implementation Preparation # Need to back up the file path: /opt/apollo/logs/access_log [root@localhost opt]# cd apollo/ [root@localhost apollo]# tree . ├── logs │ └── access_log └── test.sh # File backup storage path: /tmp/logs # The backup file is timestamped with date + %Y%m%d%H%M%S 1. Write a shell script [root@localhost tmp]# vi /opt/apollo/test.sh # Compiler# !/bin/bash # Logs are backed up to this directory. Define the variable using single quotes mypath='/tmp/logs' # echo /tmp/logs echo ${mypath} # Log to be backed up mylog='/opt/apollo/logs/access_log' # Response to /opt/apollo/logs/access_log echo ${mylog} # Timestamp, execute the command using ``, esc below time = `date +%Y%m%d%H%M%S` # Response timestamp echo ${time} #Backup the log access_log to the /tmp/logs path cp ${mylog} ${mypath}/${time}_access.log # echo ${mypath} ${mypath}/${time}_access.log 2. Execute test.sh [root@localhost apollo]# ./test.sh -bash: ./test.sh: Permission denied 3. Execute ls -la [root@localhost apollo]# ls -la total 8 drwxr-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. Grant execution permissions to the file test.sh [root@localhost apollo]# chmod +x ./test.sh [root@localhost apollo]# ls -la total 8 drwxr-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 does not report an error [root@localhost apollo]# ./test.sh /tmp/logs /opt/apollo/logs/access_log 20190120080932 /tmp/logs /tmp/logs/20190120080932_access.log 6. Edit scheduled tasks [root@localhost logs]# crontab -e no crontab for root - using an empty one crontab: installing a new crontab 7. View scheduled tasks # Execute test.sh once every minute * * * * * sh /opt/apollo/test.sh 8. Restart crond [root@localhost logs]# service crond reload Redirecting to /bin/systemctl reload crond.service You have new mail in /var/spool/mail/root 9. Write the file access_log # Need to backup file path: /opt/apollo/logs/access_log # Edit file [root@localhost logs]# vi /opt/apollo/logs/access_log # The additional content is as follows: mmmmmmmmmmmmmmmmmmmmm 10. After 1 minute, check the backup directory again [root@localhost logs]# cat 20190120083101_access.log djddjsjsjsjjsjsjsj mmmmmmmmmmmmmmmmmmmmm 11. So far, the scheduled backup task is completed. Congratulations, you have learned how to back up! 12. Delete scheduled tasks [root@localhost logs]# crontab -r You have new mail in /var/spool/mail/root 13. View scheduled tasks [root@localhost logs]# crontab -l no crontab for root The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Common usage of hook in react
>>: Detailed explanation of MYSQL log and backup and restore issues
Preface: To store multiple elements, arrays are t...
grammar: background-image: conic-gradient(from an...
Table of contents 1. Demand 2. Solution 3. The fi...
1. Two ways to specify the character set of the h...
Preface Most of our MySQL online environments use...
Preface In the last issue, we explained LinearLay...
Preface: In some application scenarios, we often ...
[LeetCode] 176. Second Highest Salary Write a SQL...
This article uses examples to explain the princip...
1. Introduction When writing animation effects fo...
#include <asm/io.h> #define ioremap(cookie,...
1. setTimeOut Print abc after 3 seconds. Execute ...
I won't say much nonsense, let's just loo...
Table of contents 1. Isolation Level READ UNCOMMI...
Table of contents - Preface - - JVM Class Loader ...