Link to home
Start Free TrialLog in
Avatar of Bob Schneider
Bob SchneiderFlag for United States of America

asked on

Move Files To Dropbox

Once a week I want to move my sql server back ups to dropbox (after deleting the old backups on dropbox). then delete my local backups.  That way I will have backups going back two weeks.  If I run this script every monday morning, will it do what I want?  (Also, is two weeks of back ups considered "safe" by industry standards?)

'If WScript.Arguments.length = 0 Then
'	Set Shell = CreateObject("Shell.Application")
  
	'Pass a bogus argument with leading blank space, say [ uac]
'	Shell.ShellExecute "wscript.exe", Chr(34) & WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
'Else
	'Set runtime variables
	Today			= Replace(Date(), "/", "-")
	SQLBakPath		= "C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup"
	DropBoxPath		= "C:\Users\Administrator\Dropbox\data_backup"
	Set FSO			= CreateObject("Scripting.FileSystemObject")
	Set SQLBakDir		= FSO.GetFolder(SQLBakPath)
	Set Shell		= WScript.CreateObject("WScript.Shell")

        'delete all files in the dropbox directory
	For Each Folder in DropBoxPath
		For Each File in Folder.Files
			File.DeleteFile
		Next
        Next

	'Move all the SQL backup files to the dropbox directory
	For Each Folder in SQLBakDir
		Set DestFolder = DropBoxPath & "\" & Folder

		For Each File in Folder.Files
			Set DestFile = DestFolder & "\" & File.Name
			FSO.MoveFile File.Path, DestFile
		Next
	Next

        'delete all files in the dropbox directory
	For Each Folder in SQLBakDir
		For Each File in Folder.Files
			File.DeleteFile
		Next
        Next

	'Unset object variables and quit
	Set Shell		= Nothing
	Set SQLBakDir		= Nothing
	Set FSO			= Nothing
'End If
WScript.Quit()

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of DcpKing
DcpKing
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ditto what Steve says too! - Mike
Avatar of Bob Schneider

ASKER

Some great points.  I am going to comment out the delete of the local files until I see how it is working.
Before re-instating the deletion, try replacing it with a move (to another local directory). That way you won't lose anything if it hasn't finished syncing ...
Agreed there. Even if it means hanging g a 1Tb USB  drive off the back might mean you could have many multiple backups then while keeping recent ones on Dropbox as DR.
Got it.  Thanks so much.