Before we begin, I assume the reader has some basic knowledge in Windows Batch Scripting.
First thing I need to create an application snapshot:
As I said before, here you can have a number of snapshots (Planning, CalcMgr...) but in this post I will use only one snapshot for demonstration.
Now here is my folder structure, I like to keep things neat and clear.
Its self explanatory:
1. Main folder will have the call me first script to define the variables etc,
2. Script folder you place whatever scripts you need to schedule for nightly runs
3. Log folder will keep the process logs
4. Backup folder will keep the latest exported/downloaded snapshots
5. Archive folder will archive the old snapshots
So Let's Get Read to Rumble!
Before I being with the files, I want to show a snapshot of the backup and archive folders.
Backup folder...
Archive folder...
Archive folder is empty, I'm keeping only five snapshots at a time in my backup folder, and then I'll move the older files to the archive folder. (will show this bit in my code in a bit).
Now my call me first script.
First I'm setting the required variables, I'm also specifying the Application Snapshot (TEST in this example) I want to process, also specifying the time stamp so I can tag my downloaded files and later archive the old ones.
So now my nightly process script.
Its pretty simple, the script is broken to:
1. Define variables
2. Login process
3. Exporting snapshot
4. Downloading snapshot
5. Logout
6. Moving the file to my backup folder
7. Archiving process
All you need to do now is execute/schedule a job to run this on daily basis (I'm not going to cover this part since its pretty standard), I'll just execute the script and check the logs.
As you can see everything is good. now my backup folder will have a new file.
Notice the time stamp, I'm keeping only the most recent, and here is my archive folder.
Run the script again, and my backup files...
Archive files...
This is done with this one liner (basically checking most recent five zip files and moving anything else to the archive folder).
And in case you're wondering about this bit.
%ERRORLEVEL% is standard windows error code returned when executing any commands, and for PBCS any exit code not equal to 0 means there is a problem (check the exit codes here ), so if I'm encountering any issues I'm simply existing the process and reporting the error. Like the following error is returned when using invalid credentials.
Voila, that's it for today.
May the Cosmos Be With You!
No comments:
Post a Comment