Solved

Move Files To Dropbox

Posted on 2014-11-15
7
182 Views
Last Modified: 2014-11-18
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

0
Comment
Question by:Bob Schneider
  • 3
  • 2
  • 2
7 Comments
 
LVL 16

Accepted Solution

by:
DcpKing earned 250 total points
ID: 40445243
It looks like it should do. However, you might want to look into putting a delay into the loop moving files into the Dropbox, as it'll be maybe a very long time for it to sync each file up to the Cloud. I'd also delay deleting the files in the backup directory until they're really there in the Dropbox directory.
*   You can check that with filesize, and also by checking if they're still locked locally (they should be when they're being moved).
*   You can also check by invoking a SQL Server job to read the various .bak files and return an appropriate result (something like "Yes" if they all open ok). You don't need to read the whole bak file - just the directory info - there's a SQL command for it.

BTW, your comment in line 32 should say "backup", not "dropbox" !

I'd also suggest that you check that your backups are as compressed as possible, for the same reason. I believe that Red Gate's backup compression is still better than Microsoft's, so you might want to consider their tool.

 hth

Mike
0
 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 250 total points
ID: 40445378
Also consider that Dropbox typically doesn't sync to the net. unless the user is logged in... so at basic level if someone logs the console off or logs off from Rdp session or power failure means rebooted and not yet logged in... then not syncing when you think it is.  I'd keep those two weeks worth or more of backups AND sync them to Dropbox too frankly even if that means providing more local disc space.

In terms of 2 weeks.... It depends. Do you run a procedure at month end on the data that you might not notice had corrupted a table till the following month end ran... couple if weeks worth fine for DR if you need to restore after failure but what if you need to get back tear old data that was deleted by someone doing dodgy Sql statement who had too much rights.

you know your data and how likely all that is or not!

Steve
0
 
LVL 16

Expert Comment

by:DcpKing
ID: 40445954
Ditto what Steve says too! - Mike
0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Closing Comment

by:Bob Schneider
ID: 40446448
Some great points.  I am going to comment out the delete of the local files until I see how it is working.
0
 
LVL 16

Expert Comment

by:DcpKing
ID: 40446453
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 ...
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40446457
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.
0
 

Author Comment

by:Bob Schneider
ID: 40450643
Got it.  Thanks so much.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question