Backup Script for Personal Computer

I am providing you below two Windows batch scripts that work as one application and perform the backup of your important files by just double-clicking on it. However, you will need to do some initial setup and then subsequent steps are very easy.

Setup Instructions:

If you are not comfortable doing the following steps, find a techie friend who can set this up for you in a few minutes.

  1. On C:\ drive create a folder called BackupScripts
  2. Go inside that folder and create two files invokeBackup.bat and backupScript.bat by taking the content of these from below.
  3. Create a shortcut on your desktop to invokeBackup.bat file.
  4. Open backupScript.bat file by right-clicking and pressing Edit. Then in that configuration section, edit the names of the folders that you want to back up and also the names of destination folders. You can use the examples that I provided in the sample script.
  5. Once you set up this backupScript.bat file, there is no need to open this any more in the future unless you decide to add brand new folders to the list of folders that you wish to back up.

How to Run the Script when you want to perform the backup:

I happen to put a reminder for myself to do a backup once a month. Here are the steps that you need to execute:

  1. Take your USB drive and plug it into your USB port. Make sure that its capacity is big enough to hold all the data that you are planning to back up.
  2. Look at the drive letter that was assigned to this USB drive and then open invokeBackup.bat file (by right-clicking the file and selecting Edit). In the script edit the variable USB_DRIVE_LETTER to the correct drive letter for your USB drive.
  3. Also in that script, edit the date. This date is useful as the script generates a log file of what it backed up and saves that into a file that starts with "BackupLog".
  4. Save the invokeBackup.bat file and exit out of it.
  5. Then run invokeBackup.bat script by double-clicking on it within C:\BackupScript folder or by double-clicking on the shortcut that you created earlier in the setup. When you double-click on it, it will pop-open a command-line window.
  6. If this is the first time doing it, then you go browse to your USB drive and look inside the backup folder and see if the files are being copied there. If they are, then everything is working fine.
  7. The backup is done when you see a message in that command-line window that the backup is done.

For example, I have 400-500Gb of data that I need to back up. This takes hours and the beauty of this script is that I can walk away from my computer and check the progress many hours later. I typically run this over night and check the status in the morning. If your backups are long, you need to make sure that the power options on your computer are set up so that your computer does NOT go into sleep if there is no activity (mouse movement) on the computer. I typically set the power option so that my laptop does not fall asleep while it is connected to power.

I strongly recommend that you perform the backup of your personal computer to two different USB drives and take one of your drives to a family member that you trust. 

Enjoy !!


__________________________________________________
invokeBackup.bat

@echo off

REM ****************************************************************
REM THIS IS THE CONFIGURATION THAT YOU NEED TO UPDATE **************
REM ****************************************************************
set USB_DRIVE_LETTER=E
set backupDate=2015_05_03
REM ****************************************************************
REM ****************************************************************



REM ****************************************************************
REM STARTING THE BACKUP ********************************************
REM ****************************************************************
set LOG_FILE=BackupLog_%backupDate%.txt
echo STARTING...
date /t
time /t

echo starting > %LOG_FILE%

REM Invoke the main script to start backing up
call backupScript.bat %USB_DRIVE_LETTER% >> %LOG_FILE%

REM Copy the log file and some finishing touches
xcopy /E /V /R /Y %LOG_FILE% C:\BackupScripts
xcopy /E /V /R /Y %LOG_FILE% %USB_DRIVE_LETTER%:\
echo DONE
date /t
time /t
echo THE BACKUP IS DONE.


REM End of script
pause

__________________________________________________

__________________________________________________
backupScript.bat

@echo off

set USB_DRIVE_LETTER=%1

mkdir USB_DRIVE_LETTER:\BACKUP

echo *********************************
echo Start backup
echo *********************************
date /t
time /t


REM *******************************************************************************************
REM THIS IS WHERE YOU CONFIGURE THE PATHS and DESTINATIONS of folders that you want to back up
REM *******************************************************************************************
set DIR01="C:\MyStuff\MyNotes"
set DIR01_DEST_A=%USB_DRIVE_LETTER%:\BACKUP\MyNotes
mkdir %DIR01_DEST_A%
xcopy /E /V /R /Y %DIR01% %DIR01_DEST_A%

set DIR02="C:\MyStuff\MyPics"
set DIR02_DEST_A=%USB_DRIVE_LETTER%:\BACKUP\MyPics
mkdir %DIR02_DEST_A%
xcopy /E /V /R /Y %DIR02% %DIR02_DEST_A%

set DIR03="C:\MyStuff\MyVideos"
set DIR03_DEST_A=%USB_DRIVE_LETTER%:\BACKUP\MyVideos
mkdir %DIR03_DEST_A%
xcopy /E /V /R /Y %DIR03% %DIR03_DEST_A%
REM ********************************************************************
REM ********************************************************************
REM ********************************************************************


date /t
time /t

echo *********************************
echo End backup
echo *********************************

REM END OF SCRIPT
___________________________________________








- almirsCorner.com -

#backup #cloudbackup #GoogleDrive #Dropbox #OneDrive #USB #USBdrive #batchscript #scripting #batchfile 

No comments:

Post a Comment