Created
March 15, 2013 01:45
-
-
Save jeffcdavis/5166896 to your computer and use it in GitHub Desktop.
If you need to run scheduled backups of a shared hosting MSSQL database. You can easily run a cron job on the following ASP script. May come in handy if you work with MSSQL databases or support older code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
dim thismonth, thisday, thisyear, location, filelename, ver, extention, abolutespath | |
thismonth= datepart("m", now()) | |
thisday=datepart("d", now()) | |
thisyear=datepart("yyyy",now()) | |
location="\\full-path-to-your-backup-folder\backup\" | |
filename="dbBackup-" & thismonth & "-" & thisday & "-" & thisyear & "_" | |
ver=1 | |
extention=".bak" | |
absolutepath=location & filename & ver & extention | |
set fso = Server.CreateObject("Scripting.FileSystemObject") | |
while (fso.FileExists(absolutepath)=True) | |
ver=ver+1 | |
absolutepath=location & filename & ver & extention | |
wend | |
Set cn = Server.CreateObject("ADODB.Connection") | |
cn.connectionString= "Provider=SQLNCLI;Server=XXXXXX;Database=XXXXXX;Uid=XXXXXX;Pwd=XXXXXX;" | |
cn.open | |
Set cmd = Server.CreateObject("ADODB.Command") | |
Set cmd.ActiveConnection = cn | |
cmd.CommandText = "FullBackup" | |
cmd.CommandType = 4 'adCmdStoredProc | |
cmd.Parameters.Refresh | |
cmd.Parameters(1) = absolutepath | |
cmd.Execute | |
cn.close | |
%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment