Backup via Batch with no 3rd party software

Here was my challenge. I need a temporary backup solution that does not use any 3rd party tools and will give a backup of the past X days (14 in my case). This solution must not be a resource hog.

My backup solution is to copy files from one server to another (or a NAS device) so that these files can be readily copied or restored from the backup location.

My scenario:
1 Server acting as a backup location. Large drives are installed on this server and NTFS file Compression is turned on. A share was created for each server that was going to be backed up using this method. By using Task scheduler, this batch file runs nightly, maps a path to the backup server, creates a folder using the date and time for the folder name, copies the files from the source machine and cleans up any folders older that X number of days.

There were a lot of challenges in designing this solution the first being creating a folder based on the date and time. Anything before 10:00am would create a space in the name causing 2 folders to be created. The second was deleting folders that were X number of days old. Thanks to the FORFILES command , this was an easy fix.

This solution requires 2 files. Backup.bat and exclude.txt. Below is the code for both. xcopy is used in this code and references the exclude.txt file to ensure that system files and other undesireables are not copied.

=====================================================
BACKUP.BAT
=====================================================

=========================================================
Exclude.txt – All exclusions should be on a line by themselves
=========================================================

 

=======================================================
Some discoveries made during this process:
1. There are hardly any system resources used with this method.
2. Backup of about 20GB took approximately 1 hour to complete. Not impressive, but it compares with a lot of 3rd party backup software, and since it uses fewer resources, there is no problem running this during production hours.
3. Locked files are not a problem since xcopy and robocopy handle them very well. (I have heard of some occasions where locked files are a problem, but most are hardware related.)
4. NTFS compression took my ~20GB backup and reduced it to under 8GB, a 40% compression ratio. This case was a healthy mix of files that could be highly compressed, such as text and html files as well as files that do not compress well such as JPG images and ZIP files (because they are already compressed).
5. I know it’s 80’s technology, but it’s cheap, fun and just works!

Comment away!

2 Replies to “Backup via Batch with no 3rd party software”

  1. Pingback: Using ShadowSpawn and Robocopy to copy in use files over a low bandwidth connection. | Xpert Notes

  2. Modified the code to allow user to set retention time with a variable and added a line to delete files older than the RetentionDays variable because the rd command does not work properly if there are files in the folder being removed.