The following script is used for scheduled backup of the entire MySQL database mysql_dump_script.sh #!/bin/bash #Save the number of backup files, retain up to 4 files number=4 #Backup save path backup_dir=/db/backup_mysql #Date dd=`date +%Y-%m-%d-%H-%M-%S` #Backup tool tool=mysqldump #Username username=root #passwordpassword=yourpassword #Database to be backed up database_name=mydb #If the folder does not exist, create it if [ ! -d $backup_dir ]; then mkdir -p $backup_dir; fi #Simple way to write mysqldump -u root -p123456 users > /root/mysqlbackup/users-$filename.sql $tool -h127.0.0.1 -u $username -p$password $database_name > $backup_dir/$database_name-$dd.sql #Write to create backup log echo "create $backup_dir/$database_name-$dd.dupm" >> $backup_dir/log.txt #Find the backup that needs to be deleted delfile=`ls -l -crt $backup_dir/*.sql | awk '{print $9 }' | head -1` #Judge whether the current number of backups is greater than $number count=`ls -l -crt $backup_dir/*.sql | awk '{print $9 }' | wc -l` if [ $count -gt $number ] then #Delete the earliest generated backup and keep only number of backups rm $delfile #Write the delete file log echo "delete $delfile" >> $backup_dir/log.txt fi centos set crontab
vi /etc/crontab Add a scheduled task Load the task to make it effective: crontab /etc/crontab View tasks: crontab -l 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:
|
<<: Three JavaScript methods to solve the Joseph ring problem
>>: A colorful cat under Linux
The default varchar type in MySQL is case insensi...
Example: We use the Python code loop_hello.py as ...
What is an index? An index is a data structure th...
Preface Recently, a problem occurred in the test ...
WeChat applet trajectory playback mainly uses pol...
Table of contents 1. When the mouse passes over t...
To facilitate the maintenance of MySQL, a script ...
If you’re new to Docker, take a look at some of t...
There are two solutions: One is CSS, using backgro...
Table of contents What is Flattening recursion to...
Table of contents 1. What is a subquery? 2. Self-...
Now most projects have begun to be deployed on Do...
Table of contents 1. Steps 1. Define buttom permi...
The fd command provides a simple and straightforw...
1. Install xshell6 2. Create a server connection ...