Backup is critical job for any System Administrator. Unlike *nix there are limited options for when we talking about the Windows System backup process.
The article is about scheduling the auto backup from existing Windows system. The script will run on any Windows systems whether the server is running on AWS EC2 or On-premises.
The testing server used here is Windows Server 2016 Server Hosted on AWS EC2.
The experimental script will copy the data from one location to other using 7-zip compression tool and then move to AWS S3 using other script.
Install the 7-zip command line tool on Windows Instance
> Go to
7-zip Download page, and Download the compatible latest command line (7-zip Extra) version.
> Extract the downloaded file to desire location (e.g. C:\Program Files\7-zip\)
> Edit existing
path for your 'System Variables' (System Properties->Advance tab->Environment Variables) and add the 7-zip path (c:\program Files\7-zip)
> Save the settings and come out of the System Properties Window.
This will install and set the path for 7-zip command line utility. You can try the example command on Windows Command prompt to verify the installation.
c:>7za --help
Install the AWS command line tool on your windows system
> Download and run the
AWS cli (64-bit) tool on computer.
> Run the .msi file and complete the installation.
Configure the AWS cli before using the AWS command line tool.
> Get the 'AWS Access Key ID' and 'AWS Secrete Access Key' from AWS IAM to allow the Windows to upload the data on AWS S3.
> Use command 'aws configure'
C:\>aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-west-2 (Set your default region)
Default output format [None]: ENTER
List the all buckets from command prompt to verify the AWS command line tool installation.
c:\>aws S3 ls
If you get the list of the buckets, then provided Access Key and Secret Access Key are correct.
Create the S3 bucket if there are no buckets already created in your account.
C:\>aws s3 mb s3://bucket-name
This will create the new bucket under AWS S3.
Verify the created bucket by using 'aws S3 ls' command again.
Create Backup (script) batch file
The below script will copy the data from one location to other and create time stamp zip file
@ECHO OFF
Set hr=%time:~0,2%
IF %hr% less 10 SET hr=0%hr:~1,1%
Set TODAY=%date:~4,2%-%date:~7,2%-%date:~10,4%-%hr%%time:~3,2%%time:~6,2%%time:~9,2%
7za a -tzip "C:\target\location\file-%TODAY%.zip" "C:\Path\of\the\data\to\be\backup" -mx5
Set root=C:\path\of\folder\from\where\you\need\to\upload\on\S3
cd %root%
aws s3 sync . s3://bucket-name/folder-name/
Save the file in formate of batch file by extension .bat.
Make Scheduler
Once the batch file created then its time to make scheduled to run the batch file automated at desire time.
> Click on 'start' and search 'Task Scheduler' in search bar
> Open the 'Task Scheduler'
> Click on 'Create Task'
> Give a name to the task in General tab
> Go to next tab 'Triggers' and create new time scheduled for your batch file to run
> Go to next tab 'Action' tab and locate the newly created batch file.
Click 'OK' to save the 'Task Scheduler'.
Easy and Fast way to set an auto-backup on Windows Servers
Comments
Post a Comment