Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How to backup server data for up to 7 days?

Posted on 2014-03-20
Medium Priority
Last Modified: 2014-03-28
This is using MS windows 2003 and MS Windows 2008 R2 servers. I need to come out a backup script (preferably using batch or robocopy) to backup selective server data into a storage. We need to keep 7-day worth of data, so those backup data that more than 7 days ago, would have to be deleted. How can I do that?

Thanks in advance.
Question by:MichaelBalack
  • 3
  • 2
  • 2
  • +1
LVL 13

Expert Comment

by:Norm Dickinson
ID: 39941926
Your best bet is to install a professional backup software which allows customizable features such as this. My favorite is http://www.acronis.com. There are also a number of cloud backup services available for a reasonable price, depending upon the volume of data being backed up, such as Rackspace.com's Jungle Disk, or Mozy.com for example.
LVL 16

Expert Comment

ID: 39942057

I'm assuming you want to do a direct copy, is that correct?  Also, do you need all of the metadata or can you just do with the file data?  

Do you want to have 7 separate copies of the data, one for each day?  Or are you backing up copies of ever-changing files and only want one copy of file that has changed at any time in the last 7 days all in one backup folder?

Batch-Driven Robocopy is great.  But there are also other options such as Deltacopy which is an rsync wrapper for Windows.  It will save you a ton of time by only copying the changed blocks of files.

DeltaCopy-rsync for Windows

Depending on your answers to the questions I can offer some examples.

- gurutc
LVL 14

Expert Comment

ID: 39942969
If your backup is already running daily from a script, and you just need to keep 7 copies, add code like this to the beginning of your backup script.

@echo off

if exist \path\to\backup7  rmdir /s /q  \path\to\backup7
if exist \path\to\backup6  ren  \path\to\backup6 \path\to\backup7
if exist \path\to\backup5  ren  \path\to\backup5 \path\to\backup6
if exist \path\to\backup4  ren  \path\to\backup4 \path\to\backup5
if exist \path\to\backup3  ren  \path\to\backup3 \path\to\backup4
if exist \path\to\backup2  ren  \path\to\backup2 \path\to\backup3
if exist \path\to\backup1  ren  \path\to\backup1 \path\to\backup2
if exist \path\to\backup   ren  \path\to\backup  \path\to\backup1

:: Then run today's backup script, putting it into \path\to\backup.

Open in new window

With the above code, backup1 will always have your backup from 1 day ago, backup5 will always have your backup from 5 days ago, etc.
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.


Author Comment

ID: 39948893
Hi ThomasMCA2,

Thanks for your script. I would rather prefer to create a backup folder that bearing with date. For example a folder named: server_backup_24032014, for backup on that day. Would it be possible?
LVL 14

Assisted Solution

ThomasMcA2 earned 996 total points
ID: 39949009
Yes, using %date to build the name of the backup folder.

The example below follows your requested date format of DDMMYYYY. However, if you use YYYYMMDD, your folders will be sorted/organized by date when sorted by name.

@echo off

:: script to build DDMMYYYY as a file name

set year=%date:~-4%
set month=%date:~3,2%

:: Make sure the month uses 2 digits
if "%month:~0,1%" == " " set month=0%month:~1,1%

set day=%date:~0,2%
if "%day:~0,1%" == " " set day=0%day:~1,1%

set folder_name=server_backup_%day%%month%%year%

:: now use %folder_name% as the destination folder name, like this:

ren todays_backup_folder %folder_name%

Open in new window

LVL 16

Accepted Solution

gurutc earned 1004 total points
ID: 39950032
Your only issue now is to remove the old backup folders.

ForFiles /P C:backups  /D -7 /C “CMD /C if @ISDIR==TRUE echo RD /Q @FILE &RD /Q /S @FILE”

Since your backup folders will have the same creation date as the date in their name this should do the trick.

- gurutc

Author Comment

ID: 39951977
Hi everyone,

Thanks for the suggestiion. I will try and wait for my updates.

Author Closing Comment

ID: 39960904
It works

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
A quick step-by-step overview of installing and configuring Carbonite Server Backup.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question