Click here to Skip to main content
6,594,932 members and growing! (15,360 online)
Email Password   helpLost your password?
Languages » C# » Applications     Intermediate

Backup Utility in C#

By rbala

A utility to backup directories and stick a datestamp on the folder, and remove folders older than N days, where N is configurable.
C++, C#.NET 1.0, Win2K, WinXP, Win2003, MFC, Dev
Posted:4 Aug 2003
Views:64,337
Bookmarked:63 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
12 votes for this article.
Popularity: 2.70 Rating: 2.50 out of 5
4 votes, 33.3%
1
2 votes, 16.7%
2
1 vote, 8.3%
3
1 vote, 8.3%
4
4 votes, 33.3%
5

Sample Image - backup.gif

Introduction

During a development project, I realized I needed something to backup my solutions every night, and be tagged with a date stamp. I looked around the Net for some DOS utilities but none really fitted the bill as far as what I was looking for. Eventually, I decided to just code it. Turned out to be super simple in C#.

Goal

My goal was to backup my solution from a source folder (e.g. C:\Data) to a backup folder (e.g. C:\Backup\Data_080403). I also wanted to only keep N number of days of backups and not let my backup folder grow infinitely. So, for instance, I wanted to keep 30 days worth of backups at most. So, whenever, any files older than 30 days were discovered, I wanted the system to delete them automatically.

Solution

I used the System.IO's Directory and DirectoryInfo classes to create folders, delete folders, and wrote a method to recursively copy folders from one location to the next. I utilized the DirectoryInfo class to figure out how old a given folder was, in order to delete it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

rbala


Member

Location: United States United States

Other popular C# articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 5 of 5 (Total in Forum: 5) (Refresh)FirstPrevNext
GeneralUse Path.DirectorySeparatorChar Pinmembercodekamfung0:13 15 Apr '04  
GeneralRe: Use Path.DirectorySeparatorChar PinsussAnonymous10:02 8 Oct '04  
GeneralRe: Use Path.DirectorySeparatorChar Pinmemberjustsml11:34 12 Dec '04  
GeneralPVCS systems PinmemberHåkan Nilsson5:48 6 Aug '03  
GeneralSuggestions PinmemberGunmen0:13 6 Aug '03  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 4 Aug 2003
Editor: Smitha Vijayan
Copyright 2003 by rbala
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project