Hi,
I'm thinking of a Backup Utility as my next project idea, but I don't really know where to start or how the backups should be made.
Can anyone shine some light on what methods of archiving backups and restoring etc. is done.
Thanks
Hi,
I'm thinking of a Backup Utility as my next project idea, but I don't really know where to start or how the backups should be made.
Can anyone shine some light on what methods of archiving backups and restoring etc. is done.
Thanks
Read through this Wikipedia Article - Backup and make sure you understand everything in it.
The simplest backup utility would be to allow a user to select a source folder, and destination folder, and just copying it across. (as that is all a backup is essentially).
But you will need some recursive folder calls to backup each folder inside folders.
One of easier methods would be:
If you just want to copy files, then you can use DirectoryInfo and FilesInfo to obtain directory, files, and perform FileCopy, FileMove, etc...
If you want to compress files at destination, then you can use the existing library like 7z, which has codes for C# as well.
To start with, I don't believe I've seen any namespace or classes in the .NET Framework specifically designed for backup/archive/restore activities. If anyone knows of any, well, enlighten us please!
At its simplest, backing up files is simply copying files from one location to another. Let's say that you have source code that you would like to maintain a backup of, and it changes a bit day by day. You could create a small console app that would simply copy all the files in the target folders to an external drive, overwriting any files that had changed since the last copy operation, and adding any new files and folders to the destination. Then use a Scheduled Task to run the utility once per day at a time when the computer is not being otherwise used -- or at least when the source is not being edited.
There are lots of methods and classes in the System.IO namespace that will make this relatively easy to do.
Some useful classes in the IO namespace are:
Here's a code sample that would give you an array of all the top-level folders just under the root of the C: drive:
string[] d = Directory.GetDirectories(@"C\", "*.*", SearchOption.TopDirectoryOnly);
DirectoryInfo[] di = new DirectoryInfo[d.Length];
for (int x = 0; x < d.Length; x++)
{
di[x] = new DirectoryInfo(d[x]);
}