In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail the shell script on how to back up the database. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Shell script 1 for backing up the database
The code is as follows:
#! / bin/bash
# specify the script shell to run
# run the script to give the user the right to execute
Bakdir=/backup
Month= `date +% m`
Day= `date +% d`
Year= `date +% Y`
Hour= `date +% k`
Min= `date +% M`
Dirname=$year-$month-$day-$hour-$min
Mkdir $bakdir/$dirname
Mkdir $bakdir/$dirname/conf
Mkdir $bakdir/$dirname/web
Mkdir $bakdir/$dirname/db
# Hot backup database
Cp / opt/mysql/my.cnf $bakdir/$dirname/db/my.cnf
Cd / opt/mysql
Mysqldump-- opt-u zhy-p-- password=1986 test > $bakdir/$dirname/db/test.sql
Mysqldump-- opt-u zhy-p-- password=1986 phpwind > $bakdir/$dirname/db/phpwind.sql
# remote copied directories must have writeable permissions
Scp-r / backup/$dirname root@10.1.1.178:/backup
Database backup script shell II
The code is as follows:
[plain]
#! / bin/bash
#--
# Target machine configuration
#--
# DBUser- > Database user name
# DBPasswd- > Database password, not null
# DBName- > Database name
# SERVER- > IP address
#--
DBUser=****
DBPasswd=****
DBName=*
SERVER=****
#--
# The local machine configuration
#--
# LocalDBUser- > Database user name
# LocalDBPasswd- > Database password,not null
# LocalDBName- > Database name
# BackupPath- > Backup path,end with'/'
# LogFile- > Log file
# num- > backup numbers
#--
LocalDBUser=**
LocalDBPasswd=***
LocalDBName=****
BackupPath=****
LogFile=****
# num=2-> Has not been completed
#--
#--
# Other configuration
#--
# IgnoreTables- > ignore tables,like this:
# IgnoreTables='- ignore-table=DBName.TableName1-ignore-table=DBName.TableName2.'
# NeedTables- > need backup tables,if you want to backup all tables,please let it empty
# like this: NeedTables='table1 table2 table3'
#--
IgnoreTables='****'
NeedTables=
# begin
NewFile= "$BackupPath" dbBackup$ (date +% y%m%d) .sql
OldFile= "$BackupPath" dbBackup$ (date +% y%m%d-- date='5 days ago') .sql
Echo "- -" > > $LogFile
Echo $(date + "% y-%m-%d% H:%M:%S") > > $LogFile
Echo $(date +% y%m%d-- date='5 days ago') > > $LogFile
Echo "--> > $LogFile
# Delete Old File
If [- f $OldFile]
Then
Rm-f $OldFile > > $LogFile 2 > & 1
Echo "[$OldFile] Delete OldFile Success!" > > $LogFile
Else
Echo "[$OldFile] No Old Backup File!" > > $LogFile
Fi
If [- f $NewFile]
Then
Echo "[$NewFile] The Backup File is exists,Can't Backup!" > > $LogFile
Echo "Begin ro recover the data...."
Mysql-u$LocalDBUser-p$LocalDBPasswd-- default-character-set='utf8' $LocalDBName > $LogFile
Else
Mysqldump-h$SERVER-u$DBUser-p$DBPasswd-- default-character-set='utf8'-- quick-- single-transaction $DBName $NeedTables $IgnoreTables > $NewFile
Echo "[$NewFile] Backup Success!" > > $LogFile
Fi
This is the end of the article on "how to implement the shell script for backing up the database". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.