In actual projects, the database needs to be backed up frequently to prevent emergencies. Some time ago, my database was invaded and all the data was lost. Fortunately, it was just a test database at the time. However, after this crisis, I began to realize this problem. First write a test database backup command: #!/bin/sh DB_USER="root" DB_PASS="1234" DB_DATA_NAME="hzl" BakDir="/data/mysql-data-back" echo "/usr/bin/mysqldump" echo "-------------------------------------------" >> $BakDir echo $(date +"%y-%m-%d %H:%M:%S") >> $BakDir cd $BakDir /usr/bin/mysqldump --no-defaults -u$DB_USER -p$DB_PASS $DB_DATA_NAME|gzip > $BakDir/db_`date +%F`.gz exit 0 The command is as above, written directly into a shell file. If the file runs successfully, a backup .gz file can be manually generated in the directory. Please note that the .sh file cannot be run at first. chmod +x sqlAutoBak.sh Okay, the above is relatively simple, let’s start the main part below, which is to make the script execute automatically every day. 1. Confirm whether crontab is installed crontab -l You can see a list of executed scripts, indicating that the installation was successful. If you don't have one, just find an installation tutorial online.
2. Add the backup script to the crontab service crontab -e Press the a key to enter edit mode Enter 0 */1 * * * /home/work/start-service.sh Press ctrl+c to exit edit mode Press shift+: and enter wq to exit crontab Then see the results 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:
|
<<: The principle and implementation of js drag effect
>>: Let's talk about Vue's mixin and inheritance in detail
Introduction: Regarding MySQL database specificat...
Solution: Just set the link's target attribute...
Create docker-compose.yml and fill in the followi...
Table of contents 1. Conventional ideas for time ...
Apache SkyWalking Apache SkyWalking is an applica...
Preface In order to reflect the difference betwee...
background It all started when a classmate in the...
This article shares the MySQL 5.7 installation an...
Basic Concepts Absolute positioning: An element b...
Recently, I need to package the project for membe...
Preface I just bought a new VPS. The data disk of...
Table of contents 1. Particle Effects 2. Load the...
Welcome to the previous canvas game series: 《VUE ...
I recently used Docker to upgrade a project. I ha...
I have read countless my.cnf configurations on th...