Script to backup important local files

Here’s a little script (Backup.cmd) I wrote to backup important stuff on my PC like VPN profiles, chrome extensions and SecureCRT sessions.

Backup.cmd
1. @echo off 

REM Delete last weeks log file
2. del “C:cmd_status_log.txt”

3. set log=”C:cmd_status_log.txt”

4. taskkill /IM chrome.exe /F
REM pause 3

echo ———————————— >> %log% 
echo         Weekly Backup Status         >> %log% 
echo ———————————— >> %log% 

5. type “C:backupfolders.txt” >> %log%

REM Delete last weeks backup file
6. del *.zip

REM ZIP the directory that’s currently being used
7. “C:Program Files7-Zip7z.exe” a -mx9 -tzip File_Backup.zip @backupfolders.txt

REM File listing of new backup file
8. “C:Program Files7-Zip7z.exe” l File_Backup.zip >> %log%

REM Rename the zip file to append the date
9. ren File_Backup.zip %date:~10,4%-%date:~4,2%-%date:~7,2%-File_Backup.zip

REM Directory Listing of new backup file
10. dir *.zip >> %log%
Here’s what each numbered line does.

1. Shut off the display of each command

2. Delete the previous backup’s log

3. Set the path and file name of the backup log file

4. Kill Chrome. This is needed to backup its extensions

5. Create this weeks backup log file

6. Delete last weeks backup file

7. Backup the files & folders listed in backupfolders.txt

8. List all the files that were just backed up into the log file

9. Rename the backup zip with a current timestamp

10. List the zip file into the log file

The next file to look at is backupfolders.txt. It’s a text file with the locations of the folders and files we want to backup. Here’s what mine looks like-

backupfolders.txt
C:UserscclarkAppDataLocalGoogleChromeUser DataDefaultLocal Storagechrome-extension*.localstorage
C:Documents and SettingsAll UsersApplication DataCiscoCisco AnyConnect VPN ClientProfileAnyConnectProfile.xml
C:VanDyke
C:Program Files (x86)Cisco SystemsVPN ClientProfiles

As you can see I backup my Chrome extensions, my AnyConnect profile, all my SecureCRT sessions, and IPSec profiles.
You can run the backup.cmd manually or automated with the task scheduler in Windows. You could also add some FTP scripting into the batch file so it backups up the zip file off site.

Leave a Reply

Your email address will not be published. Required fields are marked *