The company has three SQL Server databases, every day through SQL Server scheduled tasks to back up data locally, and then by the local upload to the data server to do the save, so repeatedly, sometimes because of busy work, forget to upload, resulting in data is replaced without backup phenomenon.
After learning about Linux, it's all just a small problem, and it doesn't need to be so troublesome to do it.
By checking the data, SQL Server can be remotely backed up, if the remote backup function of SQL Server is configured, the data is backed up to the specified data storage server every day
Converting a data backup server from Windows 7 to CentOS 6.5
Now the problem is that the database file that SQL Server passes on every day is the same file name, it will replace the original backup, so it can't save many days of data, if I want to use the way of scripting when the database backup file is passed over, I create a date folder in the current directory. The database file is then automatically moved to that folder so that the next backup will not be replaced if the loop
To prevent the disk from running out of space, I added find to the script, found the data greater than 30 days to clear, (find./-type f-mtime +30-name "*.bak" | Xargs rm-f) Only for 30 days, because the company is not very strict with the database to keep the number of days, so I look at the disk space to set
Then through the df-h to see the size of the backup disk, do a Daily mail through, tell the administrator, the day of the removal of the day of the backup, disk space more than how much.
Here is the script implementation:
#!/bin/bash
week= ' Date +%w '
# Disk Size Chkeck
Echo ' Df-h | awk ' {print $4} ' | Sed-n ' 5p ' | Sed-r ' s# (. *) #Waring/HDDF Avail \1 please chkeck disk# ' >/shell/backup.log
find/hddf/database/-maxdepth 1-mtime +24-type d! -name "Zabbix"! -name "DB"! -name "rtx*"-exec rm-rf {} \; &&\
Echo ' Df-h | awk ' {print $4} ' | Sed-n ' 5p ' | Sed-r ' s# (. *) #Waring/HDDF Avail \1 please chkeck disk# ' >>/shell/backup.log
If [$?-eq 0];then
echo "' Date +%y%m%d ' deleted successfully ' find/hddf/database/-maxdepth 1-mtime +24-type d! -name "Zabbix"! -name "DB"! -name "rtx*" ' ">>/shell/b
Ackup.log
Else
echo "' Date +%y%m%d ' Delete unsuccessful" >>/shell/backup.log
Fi
# from Email admin
Mail-s "DataBackup" [email protected] </shell/backup.log
If [$WEEK-ne 0];then
if [!-d/hddf/database/' Date +%y%m%d '];then
Mkdir-p/hddf/database/' Date +%y%m%d '
mv/hddf/database/{*.bak,*. BAK}/hddf/database/' Date +%y%m%d '/
Fi
Else
echo "Today is Sunday no data backup" >>/shell/mvdata.txt
Fi
This article is from the "Zhongliang Linux Technology blog" blog, make sure to keep this source http://zhongliang.blog.51cto.com/4507905/1917249
Small Business SQL Server Data backup Shell scripting solution