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
A recent business involves such a requirement tha...
Introduction to DNMP DNMP (Docker + Nginx + MySQL...
1. Get the mysql image docker pull mysql:5.6 Note...
There was a problem when installing the compresse...
1. Download https://dev.mysql.com/downloads/mysql...
Table of contents Index Model B+Tree Index select...
This article example shares the specific code of ...
Enter the mysql command: mysql -u+(user name) -p+...
Find the problem Recently, I found a problem at w...
10.4.1 The difference between Frameset and Frame ...
Grayscale release refers to a release method that...
Table of contents 1. Use the warehouse to create ...
The previous article on Docker mentioned the cons...
Preface This article mainly introduces the releva...
Table of contents 1. Auxiliary functions 2. Examp...