Last update at :2024-07-12,Edit by888u
At the end of the year, many of our companies have begun to take holidays, but as operation and maintenance personnel, we must always pay attention to the operation of the company's customer websites and projects. First, we monitor the stability of the server. Zuo also checked whether any of the client servers and domain names that he was responsible for expired during the Spring Festival and needed to be renewed in advance. Generally, the update data of the website is not large during the Chinese New Year, so image backup and local data backup are done uniformly.
General website files rarely change. Unless template data is modified, static files are also separated to third-party storage, so security is relatively high. The most important thing is the database. If some of our customers use cloud The databases all have automatic backup turned on, so I don’t care about this. If there are other databases that have built-in backup functions in the WEB panel used by customers, I will push them to a third-party storage backup database. For other databases, I can use scripts to customize the backup and synchronization. Upload to backup server.
First, database backup script
#!/bin/bashtool=/usr/bin/mysqldumpdd=`date +%Y%m%d`username=root #Database username password=laozuo.org #Database password database=laozuo #Database name backup_count= 2backup_dir=~/mysqlbackup #Backup database directory# Create a backup directory mkdir -p $backup_dir#Create a backup mysqldump -u root -p123456 users > /root/mysqlbackup/users-$filename.sql$tool -u $username -p$password $database > $backup_dir/$database-$dd.sql#Write backup log echo \\”create $backup_dir/$database-$dd.sql\\” >> $backup_dir/action.log#Find out the backup that needs to be deleted delfile=`ls -l -crt $backup_dir/*.sql | awk \\\'{print $9 }\\' | head -1`#Determine whether the current backup number is greater than $backup_countcount=`ls -l -crt $ backup_dir/*.sql | awk \\\'{print $9 }\\' | wc -l`if [ $count -gt $backup_count ]thenrm $delfile #Delete the earliest generated backup and keep only backup_count number of backups #Write Delete file log echo \\”delete $delfile\\” >> $backup_dir/action.logfi
We can name this file backupdata.sh and need to modify it to our own database parameters.
Second, perform backup effects
We can directly throw it into the corresponding directory and execute the script first to see if it can take effect. If it can be backed up, then we mean that the script is effective.
Third, set scheduled backup rules
0 0 * * * /backup/backupdata.sh > /dev/null 2>&1 &
We can add timing rules and set backup in the early morning. Of course, if the data is not updated a lot, then there is no need to back it up. For example, most of our company's corporate websites will not be updated during the Chinese New Year, so I will back them up in the past few days and wait until after the New Year. Even if there is a problem, I will have local backups that can be restored.
Recommended site search: vps host, .net virtual host, website registration number, Singapore server, Guangzhou server hosting, mainland China registration-free CDN, domain name space purchase, US free host, mobile proxy IP, US host rental,
p>
发表评论