Solved

# How to backup server data for up to 7 days?

Posted on 2014-03-20
752 Views
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?

0
Question by:MichaelBalack
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 2
• 2
• +1

LVL 13

Expert Comment

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.
0

LVL 16

Expert Comment

ID: 39942057
Hi,

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
0

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.


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.
0

LVL 1

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?
0

LVL 14

Assisted Solution

ThomasMcA2 earned 249 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%

0

LVL 16

Accepted Solution

gurutc earned 251 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
0

LVL 1

Author Comment

ID: 39951977
Hi everyone,

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

LVL 1

Author Closing Comment

ID: 39960904
It works
0

## Featured Post

Question has a verified solution.

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

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
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…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
###### Suggested Courses
Course of the Month7 days, 4 hours left to enroll