Small Business SQL Server Data backup Shell scripting solution

Source: Internet
Author: User

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.


    1. 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

    2. Converting a data backup server from Windows 7 to CentOS 6.5

    3. 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

    4. 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

    5. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.