Run Sql Backups/Archive DB Backup File / Copy archived file to another directory or FTP Directory
Get All available Databases using Select name from sys.databases (in 2005) or Select name from sysdatabases (in 2000).
SqlCommand objCmd = new SqlCommand(@"
BACKUP DATABASE @dbName TO DISK = @backupPath;
exec xp_cmdshell @backupCmd;", objConn);
Backup Database command takes back up for given DB.
Exec xp_cmdshell command runs dos batch files with given command.
@backupCmd paramater has actual batch command, which will do archive the file and move the file to specified destination.
For Archiving I have used Rar command, which is a tiny exe available on Internet.
@backupCmd param value is :
rar a -s -df filename.rar dbbackupname.bak && xcopy /Y filename.rar & del /F/Q filename.rar;
Above command does Three different functions,
1) Archiving using rar
2) xcopy - Moving Archiving file into given destination (Real time it would be FTP Directory)
3) Delete Archived file from Source Directory
&& - Represents If rar command executes successfully, it goes to xcopy.
& - Even if Xcopy fails, del command deletes rar file on source directory.
You can specify Backup command value in Web.Config as follows:
SqlCommand objCmd = new SqlCommand(@"
BACKUP DATABASE @dbName TO DISK = @backupPath;
exec xp_cmdshell @backupCmd;", objConn);
Backup Database command takes back up for given DB.
Exec xp_cmdshell command runs dos batch files with given command.
@backupCmd paramater has actual batch command, which will do archive the file and move the file to specified destination.
For Archiving I have used Rar command, which is a tiny exe available on Internet.
@backupCmd param value is :
rar a -s -df filename.rar dbbackupname.bak && xcopy /Y filename.rar
Above command does Three different functions,
1) Archiving using rar
2) xcopy - Moving Archiving file into given destination (Real time it would be FTP Directory)
3) Delete Archived file from Source Directory
&& - Represents If rar command executes successfully, it goes to xcopy.
& - Even if Xcopy fails, del command deletes rar file on source directory.
You can specify Backup command value in Web.Config as follows:
Comments