Thursday, August 12, 2010

SharePoint Backup Script

 This is one of the most important, yet also one of the most neglected areas of computing. Backing up your data should be at the top of your computer maintenance list, right next to virus protection. Without data backup or virus protection, you are running the risk of losing your data. And it will happen, don't think that you don't have to worry about it.

Why should you back up?
Data loss can happen in many ways. One of the most common causes is physical failure of the media the data is stored on. You probably have everything saved on your PCs hard drive. That hard drive will not live forever. To quote a friend of mine, "there are only two types of hard drives - the ones that have failed and the ones that will fail." Yes, normally hard drives will live for years without incident. But eventually they will die. It might happen gradually, by more and more bad clusters accumulating until most of the drive is unusable. Or it might happen suddenly, the hard drive just dies without warning.


Before data is sent to its storage location, it is selected, extracted, and manipulated. Many different techniques have been developed to optimize the backup procedure. These include optimizations for dealing with open files and live data sources as well as compression, encryption, and de-duplication, among others. Many organizations and individuals try to have confidence that the process is working as expected and work to define measurements and validation techniques. It is also important to recognize the limitations and human factors involved in any backup scheme. 

Full + Incrementals 
A Full + Incremental repository aims to make storing several copies of the source data more feasible. At first, a full backup (of all files) is taken. After that, any number of incremental backups can be taken. There are many different types of incremental backups, but they all attempt to only backup a small amount of data relative to the full backup. Restoring a whole system to a certain point in time would require locating the full backup taken previous to that time and the incremental backups that cover the period of time between the full backup and the particular point in time to which the system is supposed to be restored. The scope of an incremental backup is typically defined as a range of time relative to other full or incremental backups. Different implementations of backup systems frequently use specialized or conflicting definitions of these terms.
Differential backup 
A differential backup copies files that have been created or changed since the last normal or incremental backup. It does not mark files as having been backed up (in other words, the archive attribute is not cleared). If you are performing a combination of normal and differential backups, restoring files and folders requires that you have the last normal as well as the last differential backup.
Full System backup 
This type of backup is designed to allow an entire PC to be recovered to "bare metal" without any installation of operating system, application software and data. Most users understand that a backup will prevent "data" from being lost. The expense in a full system recovery is in the hours that it takes for a technician to rebuild a machine to the point of restoring the last data backup. So, a full system backup makes a complete image of the computer so that if needed, it can be copied back to the PC, usually using some type of bespoke software such as Ghost, and the user can carry on from that point.
This is a script I use to run my full backups for my SharePoint farm. It's been working, you will need to modify it to suit your environment. The portion of the script in red is where you will modify. For example the first red wants to create a folder called SPSPortal, well you might want to give it another name, it's up to you. The second read specifies the path in which the backup goes to and you might want to choose a different path on your system BUT the script will not run for the following reasons:
This path D:\SPS2007Backups\SPSPortal, the underlined part must be manually created by you first (the script doesn't create the folder, it only looks for it. When it finds it, it will create SPSPortal into it and proceed smoothly from there.
 

 Lastly, the quotes I used here " must not be the rich text format. All you do is copy the code into notepad and after saving it, change the extension name to .vbs. Then go to your Scheduled Task and schedule it, and if you prefer to run it directly, go ahead it will be fine.
 
-----------------------------------------------------------
Dim fso, f, fspec
dim yr, mo, dt, hr, min, sec

yr = Year(Now)

mo = Month(Now)
if mo < 10 Then
mo = "0" & mo
end if

dt = Day(Now)
if dt < 10 Then
dt = "0" & dt
end if

hr = Hour(Now)
if hr < 10 Then
hr = "0" & hr
end if

min = Minute(Now)
if min < 10 Then
min = "0" & min
end if

sec = Second(Now)
if sec < 10 Then
sec = "0" & sec
end if

destFolder = "SPSPortal-" & yr & "-" & mo & "-" & dt & "-" & hr & "-" & min & "-" & sec

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.CreateFolder("D:\SPS2007Backups\SPSPortal-" & yr & "-" & mo & "-" & dt & "-" & hr & "-" & min & "-" & sec)

bkFolder = f.Path
bkFolder = Replace(bkFolder, "", "\")
bkFolder = bkFolder

Set objShell = CreateObject("WScript.Shell")
objShell.CurrentDirectory = "c:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\"

objShell.Exec ("STSADM.exe -o backup -directory " & bkFolder & " -backupmethod full")
WScript.Echo "Backup Started!"
----------------------------------------------
Thanks to the Technet Forum where I got the script and it referral url to this script's location.

No comments:

Post a Comment