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
1. Enter the command mysqld --skip-grant-tables (...
Table of contents Overview The role of reverse pr...
Table of contents 1. Dockerfile 2. pom configurat...
Environmental requirements: IP hostname 192.168.1...
This article example shares the specific code of ...
Effect: css: .s_type { border: none; border-radiu...
Mongodb has a db.serverStatus() command, which ca...
Preface In order to reflect the difference betwee...
This article shares the specific code of Vue3.0 h...
We all know that the performance of applications ...
[mysql] replace usage (replace part of the conten...
1. Wireless Run PowerShell and enter the command:...
Recently, I received a requirement for function ex...
For example, when you create a new table or updat...
In JavaScript, use the removeAttribute() method o...