1. Create the backup.sh script file #!/bin/sh SOURCE_FOLDER=/data DB_FOLDER=/data/db BACKUP_FOLDER=/data/backup TM=`date +%Y%m%d%H%M%S` echo start to dump mysql database and backup files at $TM # delete old sql backup files cd $DB_FOLDER rm -rf $DB_FOLDER/*.sql #dump mysql data /usr/bin/mysqldump -h127.0.0.1 -uroot -pcz_pims@2018 --single-transaction --master-data=2 --databases ms > ms-$TM.sql echo dump db pims_hf as pims_hf-$TM.sql /usr/bin/mysqldump -h127.0.0.1 -uroot -ppass --single-transaction --master-data=2 --databases ms_workflow > pims_hf_workflow-$TM.sql echo dump db ms_workflow as pims_hf_workflow-$TM.sql /usr/bin/mysqldump -h127.0.0.1 -uroot -ppass --single-transaction --master-data=2 --databases files > files-$TM.sql echo dump db filesrv as files-$TM.sql # delete backup files which 30 days before than today find $BACKUP_FOLDER/* -type f -mtime +30 -name "*.zip" -exec rm {} \; # compress cd $SOURCE_FOLDER zip -q -r $BACKUP_FOLDER/db-$TM.zip db zip -q -r $BACKUP_FOLDER/files-new.zip files echo zip $SOURCE_FOLDER files and backup to $BACKUP_FOLDER end # Call the system method send notice msg to Dingding notification curl -X POST -d "templateCode=003&content=The file backup is successful. The backup file is saved in this directory: $BACKUP_FOLDER" http://127.0.0.1:8080/admin/do/notify/dingding echo -e end backup files at $TM '\n\n\n' 2. Create a scheduled task 1) Enter crontab -e in the command line, add the corresponding tasks, save and exit. crontab file format: * * * * * command minute hour day month week command Minutes Hours Day Month Weekday Command For example: the backup script is executed at 1:00 every week, every month, and every day, and the log is placed in the backup.log file 0 1 * * * /bin/sh /home/script/backup.sh >> /home/script/backup.log 2>&1 If the test script runs normally, you can execute the test manually 3) Query the current user's scheduled tasks. Summarize The above is the method of automatic backup script of Linux server (mysql, attachment backup) introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: Vue component to realize carousel animation
>>: Solve the 1251 error when establishing a connection between mysql and navicat
Why learn vim Linux has a large number of configu...
Preface We all know that in Linux, "everythi...
1. What is Docker? Everyone knows about virtual m...
Table of contents Preface 1. Application componen...
Copy code The code is as follows: <html> &l...
Table of contents Function Basic query functions ...
1. The role of brackets 1.1 Square brackets [ ] W...
Simply pull the image, create a container and run...
1. Preparation before installation Check the data...
In the previous article, we have realized the sim...
The code looks like this: <!DOCTYPE html> &...
Table of contents 1. Basics of audio playback in ...
I had nothing to do, so I bought the cheapest Ali...
Query the current date SELECT CURRENT_DATE(); SEL...
A reader contacted me and asked why there were pr...