Windows – Amazon S3 – Automated Backup Using S3Sync, Windows Schedule & BAT file

amazon s3amazon-web-servicesbatch-filewindows

I am trying to build an automated background backup program to backup my entire website and its heavy photo folders, using Amazon's cloud storage service, S3.

I am using S3Sync from S3Tools and have successfully tested a dummy backup using only the command line window. When I save the working command line to a batch file (.BAT) and have a Windows schedule call it, it does not work.

I can only think this has something to do with the local paths set in the command line. If I go on to my server and open the command prompt from my 'Start' button, the command prompt has a default of:

c:\Documents and Settings\administrators>_

If I go on to my server and go to c:\windows\system32 directory and open cmd.exe, the default is:

c:\windows\system32>_

Which makes me think this is the problem, I think I'm getting something like this when it's run:

c:\windows\system32c:\home\p\h\photos\private\s3sync\s3sync.exe

What is the sensible way to get around this? Can I change the default directory on the command prompt processor, when it's first loaded? Or is there a way of changing my batch command code to use the local paths correctly? Maybe this isn't the problem at all and it's something else?

Any help greatly appreciated.

My command line code:

c:\home\p\h\photos\private\s3sync\S3Sync.exe -AWSAccessKeyId xxx -AWSSecretAccessKey xxx -SyncDirection upload -LocalFolderPath "C:\home\p\h\photos\www\assets_web2" -BucketName op-photos-web -RequestEndpoint s3-eu-west-1.amazonaws.com

Best Answer

You can set the directory from the .bat file: (in your case) cd "C:\home\p\h\photos\private\s3sync\" prior to calling the S3Sync.exe. That should get you to that path, given its on the same drive.

If the file is on a different drive, issuing the C:\ (or whichever drive you'd like to navigate to) before calling the application EXE will change to that drive as well.

Other ways also include setting the starting path for the scheduled task in its properties under the Task Scheduler:

On Server 2003: Under Task tab, edit the "Start in" input box accordingly

On Server 2008: Under the Actions tab, edit the appropriate action and set the "Start in (optional):" accordingly.

Hope it helps!