I was recently on a project which required my team and I to implement a comprehensive backup scheme involving an AWS (Amazon Web Services) Windows 2012 R2 server. Critical data stored on this server had to be available at all times. My team and I decided to approach the backup task by creating snapshots of the volume that was associated with the server on a daily basis. This task was automated. The blog regarding the automation of the snapshots can be found at https://www.coveros.com/aws-snapshots-daily-backup/.

In addition to the daily snapshots in AWS, we needed another backup strategy which would allow us to restore the data if AWS ever goes down. The chances of AWS going down are low; however, we wanted to be prepared if the event did occur. In order to address the issue, the team and I decided that we would compress two folders: one that held critical company data files and another that contained the ISO image of the Windows Server. We would then transfer them to a server outside of AWS on a daily basis. We decided that the task of zipping and transferring these folders should be automated as it was repetitive. Therefore, the following scripts were used in combination to accomplish the task:

Zip.vbs

Option Explicit
Dim ObjArgs
Set ObjArgs = Wscript.Arguments

IF (ObjArgs.Count <> 3) Then
     Wscript.echo "The number of arguments should be three"
     Wscript.echo "Options : "
     Wscript.echo "For Zipping -"
     Wscript.echo "cscript Zip.vbs C [path_to_folder] [path_to_zip_file] "
     Wscript.echo "For Unzipping -"
     Wscript.echo "cscript Zip.vbs E [path_to_zip_archive] [path_to _extract]"
     Wscript.quit
End IF

Select Case ObjArgs(0)
     Case "C","c"
         Zipper ObjArgs(1), ObjArgs(2)
     Case "E","e"
         Unzipper ObjArgs(1), ObjArgs(2)
     Case Else
         Wscript.echo "No match found"
         Wscript.echo "Options : "
         Wscript.echo "For Zipping -"
         Wscript.echo "cscript Zip.vbs C [path_to_folder] [path_to_zip_file] "
         Wscript.echo "For Unzipping -"
         Wscript.echo "cscript Zip.vbs E [path_to_zip_archive] [path_to _extract]"
End Select

'
' Zipping Function
'
Function Zipper(SrcF, DestF)

     Dim fsys
     set fsys = Wscript.CreateObject("Scripting.FileSystemObject")

     IF Not (fsys.FolderExists(SrcF)) then
          Wscript.echo "Source folder could not be found so please check the path again"
          Exit Function
     End IF

     IF (fsys.FileExists(DestF)) then
          Wscript.echo " Zip file already exists"
          fsys.DeleteFile DestF
          Wscript.echo " Zip file deleted successfully."
     End IF

     ' create an empty zip file
     CreateObject("Scripting.FileSystemObject").CreateTextFile(DestF, True).Write "PK" & chr(5) & chr(6) & String(18, 0)

     dim objshell, src, des

     Set objshell = CreateObject("Shell.Application")
     Set src = objshell.NameSpace(SrcF)
     Set des = objshell.NameSpace(DestF)

     des.CopyHere(src.Items)

     Do Until des.Items.Count = src.Items.Count
          Wscript.Sleep(200)
     Loop

     Wscript.echo "Successfully zipped"

     Set fsys = Nothing
     Set objshell = Nothing
     Set src = Nothing
     Set des = Nothing

End Function

'
' Unzipping Function
'

Function Unzipper(zipF, extrF)

    Dim fsys
    set fsys = Wscript.CreateObject("Scripting.FileSystemObject")

    IF Not (fsys.FileExists(zipF)) Then
         Wscript.echo "Could not find the zip archive so please check the path again."
         Exit Function
    End IF

    IF Not (fsys.FolderExists(extrF)) Then
         Wscript.echo "Could not locate the folder to extract"
         fsys.CreateFolder(extrF)
         Wscript.echo "Folder created successFully."
    End IF

    Dim objshell, zip, extr

    Set objshell = CreateObject("Shell.Application")
    Set zip = objshell.NameSpace(zipF)
    Set extr = objshell.NameSpace(extrF)

    extr.CopyHere(zip.Items)

    Do Until extr.Items.Count = zip.Items.Count
         Wscript.Sleep(200)
    Loop
    Wscript.echo "SuccessFully extracted.!!"

    Set fsys = Nothing
    Set objshell = Nothing
    Set zip = Nothing
    Set extr = Nothing

End Function

ZipCompanyFile.bat

@echo off
echo *************Zipping Company File***********
CScript C:\Users\Administrator\Desktop\scripts\Zip.vbs C C:\MY_FOLDER C:\Users\Administrator\Desktop\zipFiles\MY_FOLDER.zip
echo *************Zipping is done***********

ZipIso.bat

@echo off
echo *************Zipping ISO Image*************
CScript C:\Users\Administrator\Desktop\scripts\Zip.vbs C D:\ISO_IMAGE C:\Users\Administrator\Desktop\zipFiles\ISO_IMAGE.zip
echo *************Zipping is done***********

FTPTransfer.txt

open ftpes://username:password@ip_address/
put C:\Users\Administrator\Desktop\zipFiles\MY_FOLDER.zip /CoverosQBBackup/MY_FOLDER.zip
put C:\Users\Administrator\Desktop\zipFiles\ISO_IMAGE.zip /CoverosQBBackup/ISO_IMAGE.zip
exit

FTPScript.bat

C:\Program^ Files\WinSCP\WinSCP.exe /script=C:\Users\Administrator\Desktop\scripts\FTPTransfer.txt

Collectively, these 5 scripts zip the two folders and transfer them to an external server. All of these scripts were tied to the Windows Task Scheduler to run at specified times. The first script that ran was the ZipCompanyFile.bat and 2 minutes after that script finished executing, the ZipIso.bat script was scheduled to run. Both of these batch files called Zip.vbs which compressed the specified source folders to the specified destination folders. After both of the folders were zipped appropriately, the FTPscript.bat and FTPTransfer.txt files came into play. The FTPScript.bat starts the WinSCP program (a free and open source FTP and SFTP client for the Windows platform) and feeds it the script “FTPTransfer.txt.” .The FTPTransfer.txt script first tells WinSCP to establish a connection with the server by providing the username, password and the IP address of the server. After a connection is successfully established, both of the zipped folders are transferred onto the server and the connection to the server is closed.

In case there is ever an issue with AWS, our backup strategy gives us the ability to restore in a timely manner. The two folders that are transferred to the external server can both be used for restoration purposes. Restoring from the zipped folder which contains the critical data files would be faster than restoring from the ISO image as all you have to do is copy the contents of that folder onto a new server and unzip it. This restoration method should be sufficient in most cases. However, if it is necessary to do a complete restoration of the entire system, one can restore from the ISO image of the server. We tested both of the solutions thoroughly by standing up Coveros-owned physical servers. In the first case, we copied the directory that contained the critical company data onto a physical server outside of AWS and unzipped it. To test the restoration from the ISO image, we stood up another physical server and restored the operating system from the ISO file. In both of these tests, we configured the Quickbooks software on the server to imitate the server in AWS. The tests were successful as the Quickbooks software performed similarly to the way it did when the server lived in AWS. This backup strategy gives us full confidence in our ability to proceed with our daily operations if any issues arise as the restoration has been tested fully.

Leave a comment

Your email address will not be published. Required fields are marked *

X