Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. How to create SQL Server backup folder

How to create SQL Server backup folder

Scheduled Pinned Locked Moved Database
databasesql-serversysadmintutorialquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    w14243
    wrote on last edited by
    #1

    SQL Server 2014/2016, using SMO. Want backup database 'dbName' of server 'serverName' to server folder 'backupFolder'. 1.Backup remote database, not backup local database. 2.The 'backupFolder' is on remote server, e.g. "D:\SQLBK\Mon". public int BackupDB(string serverName, string dbName, string backupFolder) { Server oServer = new Server(new ServerConnection(ServerName)); Backup oBackup = new Backup(); oBackup.Action = BackupActionType.Database; oBackup.Database = dbName; oBackup.Initialize = false; oBackup.Incremental = false; oBackup.LogTruncation = BackupTruncateLogType.Truncate; string sBackupFilename = Path.Combine(backupFolder, dbName + ".bak"); oBackup.Devices.AddDevice(sBackupFilename, DeviceType.File); oBackup.SqlBackup(oServer); return 0; } The 'backupFolder' is folder on 'serverName', not local folder. 1.If 'backupFolder' is not exist on 'serverName', the 'SqlBackup' command will cause exception on 'folder not exist'. 2.If use 'Directory.CreateDirectory(backupFolder)', then local folder will be created, not remote folder. So I want: 1. The 'SqlBackup' command can auto create specified backup folder. How to do it? 2. If above can't be done, then how to create 'backupFolder' on 'serverName' by SMO or other method?

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups