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
Related article: Beginners learn some HTML tags (1...
Tomcat defines multiple ClassLoaders internally s...
Recent experience in installing mysql5.7.17 free ...
What is it? Spring Boot is a sub-project of the S...
Notes on installing MySQL database, share with ev...
1. Sometimes we use ES Due to limited resources o...
Shell is a program written in C language, which i...
1. Version Information # cat /etc/system-release ...
Preface In our daily development process, sorting...
To back up multiple databases, you can use the fo...
Table of contents Common array methods Adding and...
Table of contents 1 Background 2 Create a contain...
Nextcloud is an open source and free private clou...
First: Installation of MySQL Download the MySQL s...
Table of contents 1. Main functions 2. Implementa...