'Save Backup Files to DropBox folder in Windows Server 2016

I am trying to create a PowerShell Script to backup my databases to a specific DropBox folder.

I started with my Windows Firewall, utilizing the netsh firewall call, and that works just fine. My Firewall rules have been saved successfully to my specified DropBox folder.

However, I tried a similar approach to backup my Databases to the same folder, it failed with an Access Denied error. If I change the folder to a local root folder, such as C:\DatabaseBackup, the following Firewall Script works fine.

Can someone please help me to solve this issue with DropBox? I tried to visit the DropBox site and they do offer an API, but I have no idea how to use it or if it can be used at all.
I found another site with there is an uploaded script, but it is a BASH .sh script for Unix and linus and I do not want to install the WSL on my Server for strict security reasons.

netsh advfirewall export "C:\Users\xyxAbc\Dropbox\VPSBACKUP\vps-fw-rules.wfw"


[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | out-null
$s = new-object ("Microsoft.SqlServer.Management.Smo.Server") $instance


###  Script A (failed with "Access Denied".

$bkdir = "C:\Users\xyxAbc\Dropbox\VPSBACKUP"
$dbs = $s.Databases
foreach ($db in $dbs) 
{
     if($db.Name -ne "tempdb" -or $db.Name -ne "master" -or $db.Name -ne 'model' -or $db.Name -ne'msdb') 
     {
         $dbname = $db.Name
         # $dt = get-date -format yyyyMMddHHmm #We use this to create a file name based on the timestamp 
         $dbBackup = new-object ("Microsoft.SqlServer.Management.Smo.Backup")
         $dbBackup.Action = "Database"
         $dbBackup.Database = $dbname
         $dbBackup.Devices.AddDevice($bkdir + "\" + $dbname + "_db_" + ".bak", "File")
         $dbBackup.SqlBackup($s)
     }
}


###  Script B  (Succeded without issues)

$bkdir = "C:\DatabaseBackup"
$dbs = $s.Databases
foreach ($db in $dbs) 
{
     if($db.Name -ne "tempdb" -or $db.Name -ne "master" -or $db.Name -ne 'model' -or $db.Name -ne'msdb') 
     {
         $dbname = $db.Name
         # $dt = get-date -format yyyyMMddHHmm #We use this to create a file name based on the timestamp 
         $dbBackup = new-object ("Microsoft.SqlServer.Management.Smo.Backup")
         $dbBackup.Action = "Database"
         $dbBackup.Database = $dbname
         $dbBackup.Devices.AddDevice($bkdir + "\" + $dbname + "_db_" + ".bak", "File")
         $dbBackup.SqlBackup($s)
     }
}



Solution 1:[1]

Be careful with this process. When DropBox is installed on my Server, I noticed a huge reduction of Disk Space all over sudden. For some odd reason, DropBox tried to bring my 1000 Gig space into that small 60 Gig Hard Drive, which created a reduced resources problem.

I removed and deleted all the DropBox reference from the Server and created a brand new DropBox account that will only support that Server backup needs. then, I shared that Folder with my 1000Gig account and was able to see it from my other computers.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Johnny