SQL Network Backup, that works!


01--// OMG this was a royal pain! SHARING IS CARING
02IF Object_ID('tempdb..#result') IS NOT NULL DROP TABLE #result
03CREATE TABLE(msg varchar(4000))
04
05--// in case it previously existed
06INSERT INTO #result
07exec master.dbo.xp_cmdshell 'NET USE B: /delete'
08
09--// Create mapped Drive under SQL, eh so SQL can acess it,
10--// cause now HE made it instead of us. !!THIS WAS THE CRUX!!
11--// Like our already mapped network drive wasn't good enough, dirty rat.
12
13INSERT INTO #result
14exec master.dbo.xp_cmdshell 'NET USE B: \\192.6.6.6\yourMom likesmebest /user:bob'
15INSERT INTO #result
16exec master.dbo.xp_cmdshell 'sqlcmd -E -S . -q"RESTORE DATABASE [MyPrecious] FROM DISK = N''B:\SQLBackups\MyPrecious_20091120_030000_Full.bak''"'
17
18--// Make it disappear, never temp the curious
19INSERT INTO #result
20exec master.dbo.xp_cmdshell 'NET USE B: /delete'
21
22--// See the output and do what you want with it.
23SELECT * FROM #result
24
25--// ENJOY THE RIDE

Comments :

0 comments to “SQL Network Backup, that works!”