VBS BACKUP Data Script Collection
Recently, some of the company's important servers need to back up data, so think of backup with VBS, start with PowerShell backup, and then choose VBS, the main operation is to the server's important backup data backup (clip) to the specified server directory, Then the backup of the directory file name + date for the backup, because the data is more important, and then the backup of the data after two copies to the cloud server, the most important is the local backup data through the acquisition of folder modification time to copy the latest backup data, so there are two scripts to complete, Custom execution is then performed through the scheduled tasks of the Windows system. For specific script content, see:
The data of the specified road strength will be clipped to the specified path.
Sourcefilespath= "R:\DBBackup" desfilepath= "\\192.168.4.100\Data_Backup\DataBackup" & "" &year (date) &- Month (date) &-day (date) & &hour (time) &-minute (time) & "\" Set fso=createobject (" Scripting.FileSystemObject ") If not fso. FolderExists (Desfilepath) thenfso.createfolder desfilepath ' fso.copyfile to copy files ' Fso.copyfile sourcefilepath,desfilepath ' fso.movefile moving files movefiles sourcefilespath,desfilepathend Iffunction movefiles (Ypath,spath) On error resume nextdim folder,files,file,subfolder, Subfoldersset fso = createobject ("Scripting. FileSystemObject ") Set folder = fso.getfolder (ypath) set files = folder.files ' Msgbox ypath & spahtfor each file in filesfso.movefile file,spath & "\" ' Msgbox filenextset subfolder = folder.subfoldersfor each subfolders in subfolderfoldertemp&Nbsp;= split (subfolders, "\") Foldername=foldertemp (UBound (foldertemp)) Fso.createfolder (spath& "\" & FolderName) movefiles subfolders,spath& "\" &FolderName& "\" FSO. Deletefolder subfoldersnextend function
Second, copy the backed up data to another host for two backups, the difference is that the backup to the cloud server data needs to judge the data of the first backup, the latest data to be backed up, so through the folder modification time to obtain and then through the local time to determine the most recent time in the script copy operation.
Sourcefilespath= "D:\Data_Backup" desfilepath= "\\10.12.0.51\Backup\DataBackup" & "" &year (date) &-month ( Date) &-day (date) & &hour (time) &-minute (time) & "\" Set dic=createobject (" Scripting.Dictionary ") set fso=createobject (" Scripting.FileSystemObject ") If not fso. FolderExists (Desfilepath) thenfso.createfolder desfilepath ' fso.copyfile to copy files ' Fso.copyfile sourcefilepath,desfilepath ' fso.movefile Mobile file backfolderpath=getlastmodify (Sourcefilespath) CopyFiles backfolderpath,desfilepathend if ' Move file Function movefiles (ypath,spath) On Error Resume nextdim folder,files,file,subfolder,subfoldersset fso = createobject ("Scripting. FileSystemObject ") Set folder = fso.getfolder (ypath) set files = folder.files ' Msgbox ypath & spahtfor each file in filesfso.movefile file,spath & "\" ' Msgbox filenextset subfolder = folder.subfoldersfor each subfolders in subfolderfoldertemp = Split (subfolders, "\") Foldername=foldertemp (UBound (foldertemp)) Fso.createfolder (spath& "\" &foldername) movefiles subfolders,spath& "\" &FolderName& "\" FSO. Deletefolder subfoldersnextend function "Folder Function getlastmodify" for last modified time SET FSO = createobject ("Scripting. FileSystemObject ") set folder=fso.getfolder (Folder) Set subfolders = folder.subfoldersnowdate= nowfor each subfolder in Subfoldersdic.add datediff ("s", Subfolder.datelastmodified,nowdate),subfolder.pathnext numarray=dic. Keys fsortarray numarraygetlastmodify=dic. Item (Numarray (UBound (Numarray))) End functionfunction fsortarray (Asortthisarray) dim oarraylist, ielementset&nbSp;oarraylist = createobject ( "System.Collections.ArrayList" ) for ielement = 0 to ubound (Asortthisarray) Oarraylist.add asortthisarray (iElement) NextoArrayList.Sortset fsortarray = oarraylistend function ' Copy file Function copyfiles (YPath,sPath) On error resume nextdim folder,files,file,subfolder,subfoldersset fso = CreateObject ("Scripting. FileSystemObject ") Set folder = fso.getfolder (ypath) set files = folder.files ' Msgbox ypath & spahtfor each file in filesfso.copyfile file,spath & "\" ' Msgbox filenextset subfolder = folder.subfoldersfor each subfolders in subfolderfoldertemp = split (subfolders, "\") Foldername=foldertemp (UBound (FolderTemp)) Fso.createfolder (spath& "\" &foldername) copyfiles subfolders,spath& "\" &FolderName& "\" Fso. Deletefolder&nBsp;subfoldersnextend function
This article from "Gao Wenrong" blog, declined reprint!
VBS BACKUP Data Script Collection